Page 1 of 2 12>
Topic Options
#204092 - 2012-01-20 10:23 AM BGinfo display a part of the Hostname
arjanv Offline
Fresh Scripter

Registered: 2010-03-11
Posts: 49
Loc: netherlands
Hi,

I'm using a kix script that loads bginfo.

Is it possible to display only a part of the Hostname?
all our computernames are like this AA-BBB-XXX
and i want only display the XXX on the desktop with bginfo.

thanks

Top
#204093 - 2012-01-20 11:16 AM Re: BGinfo display a part of the Hostname [Re: arjanv]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Yes this is possible.

You can get data for BGinfo from a text file (see link below). If you create the text file with kix and set the hostname to what you need it will read the correct name from the file.

 Code:
Break on

;Open text file. Create it when it does not exist.
$rc = Open(1, "Sometextfile.txt", 5)

;Get last three characters from @wksta.
$hostname = Right(@WKSTA, 3)

;Write to text file.
$rc = WriteLine(1, $hostname)

;Close text file.
$rc = Close(1)


See: http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=204013#Post204013
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#204094 - 2012-01-20 02:51 PM Re: BGinfo display a part of the Hostname [Re: Mart]
arjanv Offline
Fresh Scripter

Registered: 2010-03-11
Posts: 49
Loc: netherlands
one thing, i use bginfo script as a computer logon script, so the computername is displayed before the user login.
do think this will work with the custom code you provided?

and i was wrong, i'm using a bat file to load bginfo.exe

Top
#204095 - 2012-01-20 03:07 PM Re: BGinfo display a part of the Hostname [Re: arjanv]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Yes this should work at logon. To be sure use a local drive to store the text file.

I did not use any bat files for years and I never did any extended scripting in batch so I do not have the code ready for you but there must be some possibilities with %computername%. I'd go for a kix solution but it all depends on what you feel comfortable with.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#204096 - 2012-01-20 04:01 PM Re: BGinfo display a part of the Hostname [Re: Mart]
arjanv Offline
Fresh Scripter

Registered: 2010-03-11
Posts: 49
Loc: netherlands
ok thanks, i'm gona test it with kix to run bginfo.
your code above, do i need to place it the same kix logonscript?
and do i need to make a special BGI file, because i don't understand how your code reads the text file.

 Code:
$=SetOption("Explicit","ON")
Dim $sLocalDir	$sLocalDir="C:\BGInfo"

If Not Exist($sLocalDir) MD $sLocalDir EndIf
If Not Exist($sLocalDir+"\bginfo.exe") COPY @LSERVER+"\NETLOGON\bginfo\bginfo.exe" $sLocalDir EndIf
If Not Exist($sLocalDir+"\custom.bgi") COPY @LSERVER+"\NETLOGON\bginfo\custom.bgi" $sLocalDir EndIf

Run $sLocalDir+"\Bginfo.exe "+$sLocalDir+"\custom.bgi /timer:0 /silent /NOLICPROMPT /LOG:"+%TEMP%+"\bginfo.log"

Top
#204097 - 2012-01-20 05:00 PM Re: BGinfo display a part of the Hostname [Re: arjanv]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
 Originally Posted By: arjanv
ok thanks, i'm gona test it with kix to run bginfo.
your code above, do i need to place it the same kix logonscript?
...

Yes. You can place it just before you start BGInfo.

 Originally Posted By: arjanv

....
and do i need to make a special BGI file, because i don't understand how your code reads the text file.
....


Yes. On the right side just below the default fields you can select there is a button Custom. This allows for a custom source of the data BGInfo will display.
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#204098 - 2012-01-20 06:35 PM Re: BGinfo display a part of the Hostname [Re: Mart]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4562
Loc: USA
Just for fun... in batch...
 Code:
set pcname=%computername:~-4%
echo %pcname%


Use Kix though... and consider replacing all your batch with kix too. \:\)

Top
#204099 - 2012-01-20 09:15 PM Re: BGinfo display a part of the Hostname [Re: Allen]
arjanv Offline
Fresh Scripter

Registered: 2010-03-11
Posts: 49
Loc: netherlands
 Originally Posted By: Allen
Just for fun... in batch...
 Code:
set pcname=%computername:~-4%
echo %pcname%


Use Kix though... and consider replacing all your batch with kix too. \:\)


ok, but how to read pcname with bginfo?

Top
#204100 - 2012-01-20 10:49 PM Re: BGinfo display a part of the Hostname [Re: Mart]
arjanv Offline
Fresh Scripter

Registered: 2010-03-11
Posts: 49
Loc: netherlands
Mart. I've tested it locally by running the kix script from command promt and it works, but when i run the script twice the computername gets double and running a third time it triples the name.

is this cause because i'm still logged on and run the script?

i'm gona test it monday at work.

Top
#204101 - 2012-01-21 12:30 AM Re: BGinfo display a part of the Hostname [Re: arjanv]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
You'll have to wrap the code that creates the file in an IF statement so that it doesn't create it if it already exists.

 Code:
Break on

If Not Exist("Sometextfile.txt")
   ;Open text file. Create it when it does not exist.
   $rc = Open(1, "Sometextfile.txt", 5)

   ;Get last three characters from @wksta.
   $hostname = Right(@WKSTA, 3)

   ;Write to text file.
   $rc = WriteLine(1, $hostname)

   ;Close text file.
   $rc = Close(1)
Endif

Top
#204104 - 2012-01-22 11:50 PM Re: BGinfo display a part of the Hostname [Re: ShaneEP]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
It adds to computer name (or part of it) every time the script runs. That is why you see it two, three, four, five.....times.

You do want it to update the computer name if needed. Doesn't happen that often but what if....... Deleting it before opening the file would fix this. I made a small modification to Shane's script.

 Code:
Break on

If Exist("Sometextfile.txt")
	Del "sometextfile.txt"
EndIf

;Open text file. Create it when it does not exist.
$rc = Open(1, "Sometextfile.txt", 5)
	
;Get last three characters from @wksta.
$hostname = Right(@WKSTA, 3)
	
;Write to text file.
$rc = WriteLine(1, $hostname)
	
;Close text file.
$rc = Close(1)
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#204105 - 2012-01-23 05:11 AM Re: BGinfo display a part of the Hostname [Re: Mart]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
Honestly, I think it would be simpler if you used a registry value instead of a file. And, you wouldn't have to worry about writing over itself, or multiple entries.

Just use this line in your login script to create the registry key...
 Code:
$nul = WriteValue("HKCU\Software\Winternals\BGInfo", "hostname", Right(@WkSta,3), "REG_SZ")

And then simple create a custom entry in bginfo that points to "HKEY_CURRENT_USER\SOFTWARE\Winternals\BGInfo\hostname"

Top
#204106 - 2012-01-23 10:24 AM Re: BGinfo display a part of the Hostname [Re: ShaneEP]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4673
Loc: The Netherlands
Agreed.


Edited by Mart (2012-01-23 10:25 AM)
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
#204116 - 2012-01-26 09:54 AM Re: BGinfo display a part of the Hostname [Re: ShaneEP]
arjanv Offline
Fresh Scripter

Registered: 2010-03-11
Posts: 49
Loc: netherlands
 Originally Posted By: ShaneEP
Honestly, I think it would be simpler if you used a registry value instead of a file. And, you wouldn't have to worry about writing over itself, or multiple entries.

Just use this line in your login script to create the registry key...
 Code:
$nul = WriteValue("HKCU\Software\Winternals\BGInfo", "hostname", Right(@WkSta,3), "REG_SZ")

And then simple create a custom entry in bginfo that points to "HKEY_CURRENT_USER\SOFTWARE\Winternals\BGInfo\hostname"


Don't think this is gona work because i use a computer logon script policy.
or am i wrong?

Top
#204122 - 2012-01-26 05:52 PM Re: BGinfo display a part of the Hostname [Re: Mart]
arjanv Offline
Fresh Scripter

Registered: 2010-03-11
Posts: 49
Loc: netherlands
do you think this will work as a computer logon policy?
does kix even run with a computer logon script policy?
maybe i need a batch script eventually.

Top
#204123 - 2012-01-26 06:28 PM Re: BGinfo display a part of the Hostname [Re: arjanv]
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4562
Loc: USA
If it is a GPO script then I believe the script will have Permissions to HKLM... that would eliminate the need to write to HLCU.
Top
#204127 - 2012-01-26 09:57 PM Re: BGinfo display a part of the Hostname [Re: Allen]
arjanv Offline
Fresh Scripter

Registered: 2010-03-11
Posts: 49
Loc: netherlands
 Originally Posted By: Allen
If it is a GPO script then I believe the script will have Permissions to HKLM... that would eliminate the need to write to HLCU.

okay, so i can try to change the registry path to hklm?
i'm at work tomorrow and i'm gona test it.

Top
#204128 - 2012-01-26 11:27 PM Re: BGinfo display a part of the Hostname [Re: arjanv]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
Give it a shot. If it doesn't work then, Mart's text file solution above should still do the trick.
Top
#204129 - 2012-01-27 10:34 AM Re: BGinfo display a part of the Hostname [Re: ShaneEP]
arjanv Offline
Fresh Scripter

Registered: 2010-03-11
Posts: 49
Loc: netherlands
both provided solutions doesn't as a computer startup script.
tested situation:
policy - windows settings - scripts - startup > hostname.bat
contents of hostname.bat are: kix32.exe hostname.kix

seems that the kix isn't running at computer startup.
when using a bat script like this then it worked, but i get the fulle computername and my goal was to try only display a part of the computername.
 Code:
If Exist %WINDIR%\BGInfo.bmp Del %WINDIR%\BGInfo.bmp
\\server\netlogon\bginfo\Bginfo.exe /timer:0 /silent /NOLICPROMPT \\server\NetLogon\bginfo\hostname.bgi


anyone knows a batch script to do this?
or maybe vbs, i thought vbs will run directly without calling it from a batch file.

thanks




Edited by arjanv (2012-01-27 10:42 AM)

Top
#204130 - 2012-01-27 05:21 PM Re: BGinfo display a part of the Hostname [Re: arjanv]
ShaneEP Moderator Offline
MM club member
*****

Registered: 2002-11-29
Posts: 2127
Loc: Tulsa, OK
Kix will also run without calling it from a batch file. There's no reason it shouldn't be running. The problem is probably elsewhere. Have your tried adding the path to the kix script, rather than just "kix32.exe hostname.kix"?
Top
Page 1 of 2 12>


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1574 anonymous users online.
Newest Members
BeeEm, min_seow, Audio, Hoschi, Comet
17882 Registered Users

Generated in 0.221 seconds in which 0.033 seconds were spent on a total of 14 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org