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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VB script to be ignore if win 2k

Status
Not open for further replies.

mackem1

Technical User
Jan 16, 2009
2
GB
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



 
I now want the script to be ignored(or end) if the os is win 2k
Replace this:
win2k = True
With this:
WScript.Quit

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
I have tried this but script still seems to end prematurely no matter which OS no error messages.I think the beginning of my script must be wrong the part that determines the OS.

thanks
 
[1] If you want getOsVer, as a function, to return true for win2000 and false for not win2000, you do this.
[tt]
If InStr(osVer, "2000") Then
[red]getOsVer[/red] = True
Else
[red]getOsVer[/red] = False
End If
[/tt]
The existing form uses a variable not dimensioned inside the function, w2k. It could be a global variable accessible outside the function _if_ it is dimensioned outside the function (you did not show). If it is not, it still is not accessible outside.

[2] But the problem, as well, is that you never use the function. Do it like this.
[tt]
'use the corrected version of the function getOsVer().
if not getOsVer then 'it will be true is os is win2000
'you existing functional block (surely excluding the function getOsVer)
end if
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top