Page 1 of 1 1
Topic Options
#138112 - 2005-04-18 07:07 PM Converting VBScript to KIX
tdiehm Offline
Lurker

Registered: 2005-04-18
Posts: 3
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

Top
#138113 - 2005-04-18 07:39 PM Re: Converting VBScript to KIX
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
From what I see of that VBS, KiX can do it natively so there is no neet to convert it to KiX COM.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#138114 - 2005-04-18 07:47 PM Re: Converting VBScript to KIX
tdiehm Offline
Lurker

Registered: 2005-04-18
Posts: 3
Quote:

From what I see of that VBS, KiX can do it natively so there is no neet to convert it to KiX COM.




So does that mean I can just insert that code into my larger KiX file? I thought I read that KiX and VBS language were similar but didn't realize that I wouldn't have to change anything.

Top
#138115 - 2005-04-18 08:01 PM Re: Converting VBScript to KIX
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
No, it means that KiX has native functions that can do on one line, what several lines of COM does in VBS.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#138116 - 2005-04-19 01:03 AM Re: Converting VBScript to KIX
Allen Administrator Offline
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4572
Loc: USA
For example all the printer connections can be added with no COM at all in Kix...

Code:
 
$=addprinterconnection("\\FILE01\HP5100dtn")
$=addprinterconnection("\\FILE01\WARM-HP4000")
$=addprinterconnection("\\FILE01\WARM-HP4M")

select
case ingroup("PAWM01.HP5100dtn")
$=setdefaultprinter("\\FILE01\HP5100dtn")
case ingroup("PAWM01.HP4000")
$=setdefaultprinter("\\FILE01\WARM-HP4000")
case ingroup("PAWM01.HP4M")
$=setdefaultprinter("\\FILE01\WARM-HP4M")
endselect



I based the script above on how your script is written, which it looks like to me, gives every pc, every printer... which I doubt is a best practice. You might consider changing it to something like this:

if ingroup("groupname")
$=addprinterconnection("\\server\printershare")
$=setdefaultprinter("\\server\printshare")
endif

[all code above is untested ]
_________________________
(... better days ahead)

Top
#138117 - 2005-04-19 06:44 PM Re: Converting VBScript to KIX
tdiehm Offline
Lurker

Registered: 2005-04-18
Posts: 3
Cool, thanks for the info all!
Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 2220 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.047 seconds in which 0.025 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org