Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Don't run script if OS = Server OS

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,36102
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Don't run script if OS = Server OS
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Don't run script if OS = Server OS - 7/11/2006 12:59:47 AM   
  KnightBird

 

Posts: 27
Score: 0
Joined: 7/11/2006
Status: offline
Hi everyone. I am a serious n00b with WSH.  I am looking for a simple way to make it so that my VB logon scripts do NOT run if an administrator logs into a server?  Any Ideas?  We have a mix of Windows 2000 and Windows 2003 server.

Basically, I want the user to log in, the script starts, if OS = Sever OS skip to END.  If not then run script adn map drives and printers.

Thanks in advance for the assistance!

Jeff Kushen
 
 
Post #: 1
 
 RE: Don't run script if OS = Server OS - 7/11/2006 1:55:46 AM   
  gdewrance


Posts: 587
Score: 3
Joined: 3/16/2006
Status: offline
somthing like this?

'Check if this is a Server. If this is a server quit
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

(in reply to KnightBird)
 
 
Post #: 2
 
 RE: Don't run script if OS = Server OS - 7/11/2006 11:46:35 PM   
  KnightBird

 

Posts: 27
Score: 0
Joined: 7/11/2006
Status: offline
I dont know.. maybe.. when i try to add that to my currect script i get the following error message...

Script:  \\Servername\netlogon\logon.vbs
Line: 19     <====== Start of your code
Char: 1
Error: 0x80041021
Code: 80041021
Source: (null)


So what did i do wrong?

(in reply to gdewrance)
 
 
Post #: 3
 
 RE: Don't run script if OS = Server OS - 7/11/2006 11:59:43 PM   
  ebgreen


Posts: 4970
Score: 31
Joined: 7/12/2005
Status: offline
Please post the exact code that you are running. Change any security sensitive information of course.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to KnightBird)
 
 
Post #: 4
 
 RE: Don't run script if OS = Server OS - 7/12/2006 12:10:40 AM   
  KnightBird

 

Posts: 27
Score: 0
Joined: 7/11/2006
Status: offline
No problem.. Was just going ot do that. 

---------------------------

Set wshNetwork = CreateObject("WScript.Network")

'Check if this is a Server. If this is a server quit
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

' Standard Mappings
    wshNetwork.MapNetworkDrive "H:","\\servernam\UserData\" & wshNetwork.UserName
'End Standard Mappings

Set ADSysInfo = CreateObject("ADSystemInfo")
Set CurrentUser = GetObject("LDAP://" & ADSysInfo.UserName)
strGroups = LCase(Join(CurrentUser.MemberOf))

'If InStr(strGroups, CLEIT) Then
'If InStr(strGroups, "cn=it") Then
If InStr(strGroups, IT) Then
   wshNetwork.MapNetworkDrive "S:","\\servername\groupshare"
   wshNetwork.AddWindowsPrinterConnection "\\servername\printer1"
End If

(in reply to ebgreen)
 
 
Post #: 5
 
 RE: Don't run script if OS = Server OS - 7/12/2006 12:48:26 AM   
  ebgreen


Posts: 4970
Score: 31
Joined: 7/12/2005
Status: offline
I don't see anywhere that you set strComputer to a value.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to KnightBird)
 
 
Post #: 6
 
 RE: Don't run script if OS = Server OS - 7/12/2006 12:55:51 AM   
  KnightBird

 

Posts: 27
Score: 0
Joined: 7/11/2006
Status: offline
I didn't. 

Ok i guess what i am looking for is this.  Log into a workstation and script maps drives and printers.. that works fine.

But if i log into a server, i want the script to recognise that the OS is Windows Server 2000, or Server 2003 and quit the script.  How do i do that without lsiting 700 servers in the script?  Can't i check for an OS version or something somehow?

I am REALLY new to this..I usually jsut do this with a batch file, but i figured id try using VB script.

Thanks again for the time...Any help is appreciated!

(in reply to ebgreen)
 
 
Post #: 7
 
 RE: Don't run script if OS = Server OS - 7/12/2006 12:58:35 AM   
  gdewrance


Posts: 587
Score: 3
Joined: 3/16/2006
Status: offline
here we go


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,"98") Then Wscript.Quit
  If InStr(1,objItem.Caption,"XP") Then Wscript.Quit
  If InStr(1,objItem.Caption,"2000") Then Wscript.Quit
  If InStr(1,objItem.Caption,"2003") Then Wscript.Quit
Next

< Message edited by gdewrance -- 7/12/2006 1:04:47 AM >

(in reply to ebgreen)
 
 
Post #: 8
 
 RE: Don't run script if OS = Server OS - 7/12/2006 1:06:03 AM   
  KnightBird

 

Posts: 27
Score: 0
Joined: 7/11/2006
Status: offline
Thanks GD, i'll give it a shot.. but what if the user has a windows 2000 workstation??  Won't the 2000 caption prevent the logon script from running there too?

(in reply to gdewrance)
 
 
Post #: 9
 
 RE: Don't run script if OS = Server OS - 7/12/2006 1:09:41 AM   
  gdewrance


Posts: 587
Score: 3
Joined: 3/16/2006
Status: offline
yes
dont forget the first post "server" this was just to let you know of more ways and the strcomputer="."

(in reply to KnightBird)
 
 
Post #: 10
 
 RE: Don't run script if OS = Server OS - 7/12/2006 1:14:40 AM   
  KnightBird

 

Posts: 27
Score: 0
Joined: 7/11/2006
Status: offline
OK when the script gets to line

If InStr(1,objItem.Caption,"2000") Then Wscript.Quit

I get the message:

Script:  Logon.vbs
Line: 12
Character: 1
Error: Object Required: 'objItem'
Code: 800A01A8

Now what did i break?  Here is the complete code..

----------------------------
Set wshNetwork = CreateObject("WScript.Network")
'Check if this is a Server. If this is a server quit
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,"98") Then OSVer = "98"
  If InStr(1,objItem.Caption,"XP") Then OSVer = "XP"
  If InStr(1,objItem.Caption,"2000") Then OSVer = "2000"
  If InStr(1,objItem.Caption,"2003") Then OSVer = "2003"
Next
'If you would like the script not to run based on OS add
If InStr(1,objItem.Caption,"2000") Then Wscript.Quit
If InStr(1,objItem.Caption,"2003") Then Wscript.Quit
'display the OS ver
'WScript.Echo OSVer
' Standard Mappings
    wshNetwork.MapNetworkDrive "H:","\\servername\usershare\" & wshNetwork.UserName
'End Standard Mappings
Set ADSysInfo = CreateObject("ADSystemInfo")
Set CurrentUser = GetObject("LDAP://" & ADSysInfo.UserName)
strGroups = LCase(Join(CurrentUser.MemberOf))
'If InStr(strGroups, CLEIT) Then
'If InStr(strGroups, "cn=it") Then
If InStr(strGroups, IT) Then
   wshNetwork.MapNetworkDrive "S:","\\servername\shareddata"
   wshNetwork.AddWindowsPrinterConnection "\\servername\printer"
End If

(in reply to gdewrance)
 
 
Post #: 11
 
 RE: Don't run script if OS = Server OS - 7/12/2006 1:32:44 AM   
  KnightBird

 

Posts: 27
Score: 0
Joined: 7/11/2006
Status: offline
I think i solved it.....  what do you think?


------------------------------

Set wshNetwork = CreateObject("WScript.Network")
'Check if this is a Server. If this is a server quit
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,"98") Then OSVer = "98"
  If InStr(1,objItem.Caption,"XP") Then OSVer = "XP"
  If InStr(1,objItem.Caption,"2000") Then OSVer = "2000"
  If InStr(1,objItem.Caption,"2003") Then OSVer = "2003"
Next
'If you would like the script not to run based on OS add
If OSVER = "2000" Then Wscript.Quit
If OSVER = "2003" Then Wscript.Quit



-----------------------

This seems to be working on servers, not running and on XP workstations.  But there will be windows 2000 workstations, so how do i get around that?


(in reply to KnightBird)
 
 
Post #: 12
 
 RE: Don't run script if OS = Server OS - 7/12/2006 1:32:52 AM   
  gdewrance


Posts: 587
Score: 3
Joined: 3/16/2006
Status: offline
this is what I meant the first time

Set wshNetwork = CreateObject("WScript.Network")
'Check if this is a Server. If this is a server quit
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,"98") Then Wscript.Quit
  If InStr(1,objItem.Caption,"XP") Then Wscript.Quit
  If InStr(1,objItem.Caption,"Server") Then Wscript.Quit
  If InStr(1,objItem.Caption,"2003") Then Wscript.Quit
Next

Take a look at Marks script
http://www.tek-tips.com/faqs.cfm?fid=5798

< Message edited by gdewrance -- 7/12/2006 1:40:23 AM >

(in reply to KnightBird)
 
 
Post #: 13
 
 RE: Don't run script if OS = Server OS - 7/12/2006 2:01:56 AM   
  KnightBird

 

Posts: 27
Score: 0
Joined: 7/11/2006
Status: offline
Thanks!  That cuts out a little code..

And it works perfectly!  And that is a handy reference script too!

Thanks for all the help!



(in reply to gdewrance)
 
 
Post #: 14
 
 RE: Don't run script if OS = Server OS - 7/17/2006 4:29:31 AM   
  saturnguy01

 

Posts: 1
Score: 0
Joined: 7/17/2006
Status: offline
Now what about deteremining if the server is 64bit or 32 bit? Since MS uses the same build numbers for both version have you guys found a way to determine that information?

(in reply to KnightBird)
 
 
Post #: 15
 
 RE: Don't run script if OS = Server OS - 7/17/2006 8:26:57 AM   
  kirrilian


Posts: 628
Score: 3
Joined: 3/15/2005
From:
Status: offline
I dont have a 64bit version of windows here at work to test it out, but I'm curious to see if the caption information from the Win32_OperatingSystem WMI class would have it.

If someone that has a 64bit version of windows could test it out with this script (taken from the script center):

Set dtmConvertedDate = CreateObject("WbemScripting.SWbemDateTime")

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
   & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colOperatingSystems = objWMIService.ExecQuery _
   ("Select * from Win32_OperatingSystem")

For Each objOperatingSystem in colOperatingSystems
   Wscript.Echo "Boot Device: " & objOperatingSystem.BootDevice
   Wscript.Echo "Build Number: " & objOperatingSystem.BuildNumber
   Wscript.Echo "Build Type: " & objOperatingSystem.BuildType
   Wscript.Echo "Caption: " & objOperatingSystem.Caption
   Wscript.Echo "Code Set: " & objOperatingSystem.CodeSet
   Wscript.Echo "Country Code: " & objOperatingSystem.CountryCode
   Wscript.Echo "Debug: " & objOperatingSystem.Debug
   Wscript.Echo "Encryption Level: " & objOperatingSystem.EncryptionLevel
   dtmConvertedDate.Value = objOperatingSystem.InstallDate
   dtmInstallDate = dtmConvertedDate.GetVarDate
   Wscript.Echo "Install Date: " & dtmInstallDate
   Wscript.Echo "Licensed Users: " & _
       objOperatingSystem.NumberOfLicensedUsers
   Wscript.Echo "Organization: " & objOperatingSystem.Organization
   Wscript.Echo "OS Language: " & objOperatingSystem.OSLanguage
   Wscript.Echo "OS Product Suite: " & objOperatingSystem.OSProductSuite
   Wscript.Echo "OS Type: " & objOperatingSystem.OSType
   Wscript.Echo "Primary: " & objOperatingSystem.Primary
   Wscript.Echo "Registered User: " & objOperatingSystem.RegisteredUser
   Wscript.Echo "Serial Number: " & objOperatingSystem.SerialNumber
   Wscript.Echo "Version: " & objOperatingSystem.Version
Next

_____________________________

Have you searched here ?
VBScript Fundamentals
My Site

(in reply to saturnguy01)
 
 
Post #: 16
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Don't run script if OS = Server OS Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts