Hi can anyone help. I'm really new to VB scripting. I have wrote the below script and it work fab but I now want the script to be ignored(or end) if the os is win 2k.Basically I only want Win XP or above to recognise the script. I would be really greatful if anyone can assist. I have just can't get my end,if,else statements right. I need to check the os in a Active Directory environment.
Function getOsVer()
Dim SystemSet, system, osVer
Set SystemSet = _
GetObject("winmgmts:").InstancesOf ("Win32_OperatingSystem")
For each System in SystemSet
osVer = System.Caption
'# DETERMINE IF OS IS 2000 PRO/SERVER
If InStr(osVer, "2000") Then
win2k = True
Else
win2k = False
End If
Next
End Function
'On Error Resume next
Dim objFSO: Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim WshShell: Set WshShell = CreateObject("Wscript.Shell")
Dim objProcess: Set objProcess = WshShell.Environment("Process")
Dim strLogonSvr: strLogonSvr = objProcess("LogonServer")
Dim strSysDrv: strSysDrv = WshShell.ExpandEnvironmentStrings("%SYSTEMDRIVE%")
Dim strSysRoot: strSysRoot = WshShell.ExpandEnvironmentStrings("%SYSTEMROOT%")
Dim objFolder, objFile1, objFile2
' Define source, destination paths and filenames.
Dim strSrc: strSrc = strLogonSvr & "\Netlogon\file\file\"
Dim strDest: strDest = strSysRoot & "\system32\"
Dim strTempDest: strTempDest = strSysRoot & "\system32\Temp\"
Dim strFile1: strFile1 = "file.exe"
Dim strFile2: strFile2 = "file.bgi"
' Note If..Exists. Then, Else ... End If construction
' Folder creation process. If folder not there, then create.
If objFSO.FolderExists(strDest) Then
Set objFolder = objFSO.GetFolder(strDest)
Else
Set objFolder = objFSO.CreateFolder(strDest)
End If
If err.number = vbEmpty then
Set WshShell = CreateObject("WScript.Shell")
Else
WScript.echo "VBScript Error: " & err.number
End If
If objFSO.FolderExists(strTempDest) Then
Set objFolder = objFSO.GetFolder(strTempDest)
Else
Set objFolder = objFSO.CreateFolder(strTempDest)
End If
If err.number = vbEmpty then
Set WshShell = CreateObject("WScript.Shell")
Else
WScript.echo "VBScript Error: " & err.number
End If
' If strFile1 not there, then copy.
If objFSO.FileExists(strDest & strFile1) Then
Set objFile1 = objFSO.GetFile(strDest & strFile1)
Else
objfso.CopyFile strSrc & strFile1, strTempDest & strFile1
objfso.MoveFile strTempDest & strFile1, strDest & strFile1
End If
' If strFile2 not there, then copy.
If objFSO.FileExists(strDest & strFile2) Then
Set objFile2 = objFSO.GetFile(strDest & strFile2)
Else
objfso.CopyFile strSrc & strFile2, strTempDest & strFile2
objfso.MoveFile strTempDest & strFile2, strDest & strFile2
End If
Set oShell = CreateObject("Wscript.Shell")
oShell.Run "regedit.exe /s " & "%logonserver%\NETLOGON\file\registy.reg",0,true
oShell.Run "regedit.exe /s " & "%logonserver%\NETLOGON\file\registry.reg",0,true
'popup = WshShell.Popup("Script completed.",0, "CopyfileandRegistry.vbs",64)
' Clean Up process.
set objfso = nothing
Set objFolder = nothing
Set WshShell = nothing
Set objFile1 = nothing
Set objFile2 = nothing
Set oShell = nothing
WScript.Quit
thanks
Function getOsVer()
Dim SystemSet, system, osVer
Set SystemSet = _
GetObject("winmgmts:").InstancesOf ("Win32_OperatingSystem")
For each System in SystemSet
osVer = System.Caption
'# DETERMINE IF OS IS 2000 PRO/SERVER
If InStr(osVer, "2000") Then
win2k = True
Else
win2k = False
End If
Next
End Function
'On Error Resume next
Dim objFSO: Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim WshShell: Set WshShell = CreateObject("Wscript.Shell")
Dim objProcess: Set objProcess = WshShell.Environment("Process")
Dim strLogonSvr: strLogonSvr = objProcess("LogonServer")
Dim strSysDrv: strSysDrv = WshShell.ExpandEnvironmentStrings("%SYSTEMDRIVE%")
Dim strSysRoot: strSysRoot = WshShell.ExpandEnvironmentStrings("%SYSTEMROOT%")
Dim objFolder, objFile1, objFile2
' Define source, destination paths and filenames.
Dim strSrc: strSrc = strLogonSvr & "\Netlogon\file\file\"
Dim strDest: strDest = strSysRoot & "\system32\"
Dim strTempDest: strTempDest = strSysRoot & "\system32\Temp\"
Dim strFile1: strFile1 = "file.exe"
Dim strFile2: strFile2 = "file.bgi"
' Note If..Exists. Then, Else ... End If construction
' Folder creation process. If folder not there, then create.
If objFSO.FolderExists(strDest) Then
Set objFolder = objFSO.GetFolder(strDest)
Else
Set objFolder = objFSO.CreateFolder(strDest)
End If
If err.number = vbEmpty then
Set WshShell = CreateObject("WScript.Shell")
Else
WScript.echo "VBScript Error: " & err.number
End If
If objFSO.FolderExists(strTempDest) Then
Set objFolder = objFSO.GetFolder(strTempDest)
Else
Set objFolder = objFSO.CreateFolder(strTempDest)
End If
If err.number = vbEmpty then
Set WshShell = CreateObject("WScript.Shell")
Else
WScript.echo "VBScript Error: " & err.number
End If
' If strFile1 not there, then copy.
If objFSO.FileExists(strDest & strFile1) Then
Set objFile1 = objFSO.GetFile(strDest & strFile1)
Else
objfso.CopyFile strSrc & strFile1, strTempDest & strFile1
objfso.MoveFile strTempDest & strFile1, strDest & strFile1
End If
' If strFile2 not there, then copy.
If objFSO.FileExists(strDest & strFile2) Then
Set objFile2 = objFSO.GetFile(strDest & strFile2)
Else
objfso.CopyFile strSrc & strFile2, strTempDest & strFile2
objfso.MoveFile strTempDest & strFile2, strDest & strFile2
End If
Set oShell = CreateObject("Wscript.Shell")
oShell.Run "regedit.exe /s " & "%logonserver%\NETLOGON\file\registy.reg",0,true
oShell.Run "regedit.exe /s " & "%logonserver%\NETLOGON\file\registry.reg",0,true
'popup = WshShell.Popup("Script completed.",0, "CopyfileandRegistry.vbs",64)
' Clean Up process.
set objfso = nothing
Set objFolder = nothing
Set WshShell = nothing
Set objFile1 = nothing
Set objFile2 = nothing
Set oShell = nothing
WScript.Quit
thanks