Hi all,

I'm trying to convert this VBScript to KIX so I can enter it into a larger KIX file. I saw this thread at http://www.kixtart.org/ubbthreads/showflat.php?Cat=&Board=UBB12&Number=83646 on how to convert but I'm not sure how to get it to run. Do I just put it in a batch file???

Any help would be appreciated, the actual code is below. Basically it's just a script to add/remove printers.

Thanks.


On Error Resume Next

DIM FSO, WshSysEnv, WshNetwork, objSysInfo, objUser
DIM strVersion, objPrintVer

strVersion = "004"

Set FSO=CreateObject ("Scripting.FileSystemObject")
Set WshSysEnv = WshShell.Environment("PROCESS")
Set WshNetwork = WScript.CreateObject("WScript.Network")
Set objSysInfo = CreateObject("ADSystemInfo")
Set objUser = GetObject ("LDAP://" & objSysInfo.UserName)


'If Not FSO.FileExists (WshSysEnv("USERPROFILE") & "\printver." & strVersion) Then
If Not FSO.FileExists ("c:\printver." & strVersion) Then

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Remove all networked printers
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colInstalledPrinters = objWMIService.ExecQuery("Select * from Win32_Printer")
For Each objPrinter in colInstalledPrinters
If Left(objPrinter.Name,2) = "\\" Then
WshNetwork.RemovePrinterConnection objPrinter.Name
End If
Next

'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' General printers

strPrinterPath = "\\FILE01\HP5100dtn"
WshNetwork.AddWindowsPrinterConnection strPrinterPath
If ChkGroup("PAWM01.HP5100dtn") Then
Wscript.Sleep 2000
WshNetwork.SetDefaultPrinter strPrinterPath
End If

strPrinterPath = "\\FILE01\WARM-HP4000"
WshNetwork.AddWindowsPrinterConnection strPrinterPath
If ChkGroup("PAWM01.HP4000") Then
Wscript.Sleep 2000
WshNetwork.SetDefaultPrinter strPrinterPath
End If

strPrinterPath = "\\FILE01\WARM-HP4M"
WshNetwork.AddWindowsPrinterConnection strPrinterPath
If ChkGroup("PAWM01.HP4M") Then
Wscript.Sleep 2000
WshNetwork.SetDefaultPrinter strPrinterPath
End If

strPrinterPath = "\\FILE01\WARM-HP4MV"
WshNetwork.AddWindowsPrinterConnection strPrinterPath
If ChkGroup("PAWM01.HP4MV") Then
Wscript.Sleep 2000
WshNetwork.SetDefaultPrinter strPrinterPath
End If

strPrinterPath = "\\FILE01\XeroxDoc"
WshNetwork.AddWindowsPrinterConnection strPrinterPath
If ChkGroup("PAWM01.XeroxColor") Then
Wscript.Sleep 2000
WshNetwork.SetDefaultPrinter strPrinterPath
End If


Set objPrintVer = FSO.CreateTextFile ("c:\printver." & strVersion, True, False)
objPrintVer.Writeline ("This is a flag file... if deleted the PAWM01-P.VBS script will execute again.")
objPrintVer.Close
Set objPrintVer = Noting

End If

Set FSO = Nothing
Set WshSysEnv = Nothing
Set WshNetwork = Nothing
Set objSysInfo = Nothing
Set objUser = Nothing
strVersion = ""



'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Function to check membership of a group
Function ChkGroup(strGroup)

ChkGroup = False
On Error Resume Next
Set oGroup = GetObject("WinNT://AI-ENGSVCS/" & strGroup)
If Err.Number >= 0 Then

Set objSysInfo = CreateObject("ADSystemInfo")
Set objUser = GetObject ("LDAP://" & objSysInfo.UserName)

If oGroup.IsMember("WinNT://TESTDOMAIN/" & Right(objUser.Name,Len(objUser.Name) -3)) Then
chkGroup = True
End If

Set oGroup = Nothing
Set objUser = Nothing
Set objSysInfo = Nothing

End If

End Function