Help - Search - Members - Calendar
Full Version: Need help for logon script , Urgent.
MSFN Forums > Coding, Scripting and Servers > Programming (C++, Delphi, VB, etc.)

   
Google Internet Forums Unattended CD/DVD Guide
justhink
Nedd to run a vbs script on logon, which update group policy, but there are few clients are using 2000 professional, so GPUPDATE won't use, hav to use SECEDIT so, can some 1 tell me how to determin OS via VBS so it can run GPEDIT on XP clients and SECEDIT on 2000 clients,

Please help me, urgent,

Script is >
QUOTE
Set objShell = CreateObject("WScript.Shell")

;this will run on XP
objShell.Run "gpupdate /force", 1, True

;But i don't know how... sad.gif

;This will for 2000
objShell.Run "SECEDIT /REFRESHPOLICY USER_POLICY /ENFORCE", 1, True
bennebiest
To determine the Windows version:

CODE
strComputer = "."

Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSettings = objWMIService.ExecQuery _
    ("Select * from Win32_OperatingSystem")
For Each OS In colSettings
    Wscript.Echo OS.Caption
    WScript.Echo OS.Version
Next


For XP for example, it will give this output:

CODE
Microsoft Windows XP Professional
5.1.2600


You can put the output in a variable and make a Select Case to execute te gpupdate or secedit, dependig on the Windows version.

Happy coding.
justhink
QUOTE (bennebiest @ Jul 10 2008, 05:03 PM) *
To determine the Windows version:

CODE
strComputer = "."

Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSettings = objWMIService.ExecQuery _
    ("Select * from Win32_OperatingSystem")
For Each OS In colSettings
    Wscript.Echo OS.Caption
    WScript.Echo OS.Version
Next


For XP for example, it will give this output:

CODE
Microsoft Windows XP Professional
5.1.2600


You can put the output in a variable and make a Select Case to execute te gpupdate or secedit, dependig on the Windows version.

Happy coding.



I can do this much..

QUOTE
On Error Resume Next
Set objShell = CreateObject("WScript.Shell")
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 objShell.Run "notepad.exe", 1, True
Next
objShell.Run "calc.exe", 1, True


This script can detect and run specific file for on specific os, there is a problem, when i run it on Windows 2003 it's opening both notepad and calculator, but on XP it opens calculator only,

so how do i add stop execution after it open notepad on 2003..


Thanks..
bennebiest
Try this one:

CODE
strComputer = "."

Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSettings = objWMIService.ExecQuery _
    ("Select * from Win32_OperatingSystem")
For Each OS In colSettings
    'Wscript.Echo OS.Caption
    'WScript.Echo OS.Version
    
    strOS = OS.Caption
    WScript.Echo strOS
    
    Select Case strOS
        
        Case "Microsoft Windows XP Professional"
        WScript.Echo "XP"
        'paste your gpupdate code
        
        Case "Microsoft Windows 2000 Professional"
        WScript.Echo "2000"
        'paste your secedit code
    
    End Select
Next
gunsmokingman
Try this you will have to add the code you want it to run.
QUOTE
CODE
Option Explicit
Dim Act :Set Act = CreateObject("WScript.Shell")
Dim objItem, colItems, objWMIService, strComputer
  strComputer = "."
  Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
  Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48)
    For Each objItem in colItems
     If InStr(objItem.Caption,"2000") Then
      WScript.Echo objItem.Caption
     End If
     If InStr(objItem.Caption,"2003") Then
      WScript.Echo objItem.Caption
     End If
     If InStr(LCase(objItem.Caption),Lcase("XP")) Then
      WScript.Echo objItem.Caption
     End If
    Next
justhink
QUOTE (gunsmokingman @ Jul 10 2008, 07:20 PM) *
Try this you will have to add the code you want it to run.
QUOTE
CODE
Option Explicit
Dim Act :Set Act = CreateObject("WScript.Shell")
Dim objItem, colItems, objWMIService, strComputer
  strComputer = "."
  Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
  Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48)
    For Each objItem in colItems
     If InStr(objItem.Caption,"2000") Then
      WScript.Echo objItem.Caption
     End If
     If InStr(objItem.Caption,"2003") Then
      WScript.Echo objItem.Caption
     End If
     If InStr(LCase(objItem.Caption),Lcase("XP")) Then
      WScript.Echo objItem.Caption
     End If
    Next



This 1 works fine but after few little modification, but thank you..

CODE
Option Explicit
Dim objItem, colItems, objWMIService, strComputer, objShell
strComputer = "."
Set objShell = CreateObject("WScript.Shell")
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem",,48)
For Each objItem in colItems
    If InStr(objItem.Caption,"2000") Then
        objShell.Run "secedit /refreshpolicy", 1, True
    End If
    If InStr(LCase(objItem.Caption),Lcase("XP")) Then
        objShell.Run "gpupdate", 1, True
    End If
Next


Google Internet Forums Unattended CD/DVD Guide
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.