Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Amend Login Script So It Doesn't Run On Servers

Status
Not open for further replies.

djrampant

Technical User
Oct 30, 2002
15
0
0
GB
Hi,

I've used some resources around the net and have written a vb login script that does everything I need it to do.

I want to link this to the whole domain so it applies to everybody, however I do not want this script to run if the user logs on to a server.

I know this can be done with the old kix scripts, but does anyone know how to do this with vb script?

Thanks in advance.
 
check for the OS that the script is running on?
have a check in the script from something unique to a server or to a client??? we had various environment variables specifc to a client machine?

either way you will ahve to get your server lot to accept that a script will run for a short time to logon who is logging on where and what OS they are logging onto and then bomb out on condition
 
Hi thanks for your reply.

I dont mind how the script does it to be honest.

It can be via os or via machine name as there are only 4 servers here.

I am the "server lot" so i dont mind the script running in part at all ;)
 
start your vbscript with something like

strComputerName = WshShell.ExpandEnvironmentStrings("%computername%")
Select Case UCase(strComputerName)
Case "SERVERA", "SERVERB", "SERVERC"
'LOG THE FACT TO A CENTRAL %COMPUTERNAME%.TXT FILE?
Wscript.Quit
End Select
 
A better way would be to detect the OS and exit if it contains the word server in it.

Code:
On Error Resume Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48)
For Each objItem in colItems
	If InStr(1,objItem.Caption,"Server") Then Wscript.Quit
Next

You can also block it from the GPO level.

I hope you find this post helpful.

Regards,

Mark
 
Thanks Mark that appears to work.

I have added the code to the top of the file and it all works but is there a way a can streamline this because i think it may be more complicated than it needs to be. For example the strComputer statement is included twice.

I wont be supporting this script for very long as I am on a short term contract and want to keep the script as simple as possible.

A sample of my code is below.

Thanks
Code:
ON ERROR RESUME NEXT

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48)
For Each objItem in colItems
    If InStr(1,objItem.Caption,"Server") Then Wscript.Quit
Next

Dim WSHShell, WSHNetwork, objDomain, DomainString, UserString, UserObj, Path

Set WSHShell = CreateObject("WScript.Shell")
Set WSHNetwork = CreateObject("WScript.Network")

'Automatically find the domain name
Set objDomain = getObject("LDAP://rootDse")
DomainString = objDomain.Get("dnsHostName")
WinDir = WshShell.ExpandEnvironmentStrings("%WinDir%")

'Grab the user name
UserString = WSHNetwork.UserName

'Bind to the user object to get user name and check for group memberships later
Set UserObj = GetObject("WinNT://" & DomainString & "/" & UserString)

'Grab the computer name
strComputer = WSHNetwork.ComputerName

'Map drives needed by all
WSHNetwork.MapNetworkDrive "v:", "\\galaxy\public",True


'Clean Up Memory We Used
set UserObj = Nothing
set GroupObj = Nothing
set WSHNetwork = Nothing
set DomainString = Nothing
set WSHSHell = Nothing
Set WSHPrinters = Nothing
  

'Quit the Script
wscript.quit
 
Just move this
Code:
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48)
For Each objItem in colItems
    If InStr(1,objItem.Caption,"Server") Then Wscript.Quit
Next

Under the existing line
strComputer = WSHNetwork.ComputerName

And eliminate the
strComputer = "."

I hope you find this post helpful.

Regards,

Mark
 
mrmovie: check for the OS that the script is running on?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top