#120851 - 2004-06-08 07:04 PM
VBSCRIPT converted to KIXTART (Set Statement)
|
ktodi
Getting the hang of it
Registered: 2002-03-29
Posts: 60
|
The script posted below was a working vbscript that I am attempting to now run from kixtart. I am getting an error on first SET statement then the script quits. What change should I make to get it to work?
$w2kwxp = @PRODUCTTYPE = "Windows 2000 Professional" OR @PRODUCTTYPE = "Windows XP Professional"
If $w2kwxp Dim $WSHNetwork, $fso Set $WSHNetwork = CreateObject("WScript.Network") Set $fso = CreateObject("Scripting.FileSystemObject")
Dim $LogEntry $UName = @USERID $DName = @LDOMAIN $CName = @WKSTA
Dim $Status $Status = "NotLogged" If $fso.FileExists("\\nserv\wkslogs$\" & $CName & ".txt") Then Dim $SearchString $SearchString = ($DName & "\" & $UName) Dim $ParseFile, $TextStream, $TextLine Set $ParseFile = $fso.GetFile("\\nserv\wkslogs$\" & $CName & ".txt") Set $TextStream = $ParseFile.OpenAsTextStream Do While Not $TextStream.AtEndOfStream $TextLine = $TextStream.ReadLine If InStr(1,$TextLine,$SearchString,1) <> 0 Then Status = "AlreadyLogged" End If Loop $TextStream.Close End If
If $Status = "NotLogged" Then Dim $Logfile $Logfile = ("\\nserv\wkslogs$\" & $CName & ".txt") Dim ologfile Set $ologfile = fso.OpenTextFile($Logfile, 8, True) $ologfile.writeline ($DName & "\" & $UName) $ologfile.close End If End If
Sleep 7
Exit
|
|
Top
|
|
|
|
#120854 - 2004-06-08 07:28 PM
Re: VBSCRIPT converted to KIXTART (Set Statement)
|
ktodi
Getting the hang of it
Registered: 2002-03-29
Posts: 60
|
Thanks for the advice and help. How would you poputale the string then without using variables? Would you create arrays?
|
|
Top
|
|
|
|
#120857 - 2004-06-08 07:43 PM
Re: VBSCRIPT converted to KIXTART (Set Statement)
|
ktodi
Getting the hang of it
Registered: 2002-03-29
Posts: 60
|
Her is the script with the "Do" and "set" commands removed and the "&" replaced with +. The script does not work and I get no errors, any advice?
$w2kwxp = @PRODUCTTYPE = "Windows 2000 Professional" OR @PRODUCTTYPE = "Windows XP Professional"
If $w2kwxp Dim $WSHNetwork, $fso $WSHNetwork = CreateObject("WScript.Network") $fso = CreateObject("Scripting.FileSystemObject")
Dim $LogEntry $UName = @USERID $DName = @LDOMAIN $CName = @WKSTA
Dim $Status $Status = "NotLogged" If $fso.FileExists("\\nserv\wkslogs$\" + $CName + ".txt") Then Dim $SearchString $SearchString = ($DName + "\" + $UName) Dim $ParseFile, $TextStream, $TextLine $ParseFile = $fso.GetFile("\\nserv\wkslogs$\" + $CName + ".txt") $TextStream = $ParseFile.OpenAsTextStream While Not $TextStream.AtEndOfStream $TextLine = $TextStream.ReadLine If InStr(1,$TextLine,$SearchString,1) <> 0 Then Status = "AlreadyLogged" End If Loop $TextStream.Close End If
If $Status = "NotLogged" Then Dim $Logfile $Logfile = ("\\nserv\wkslogs$\" + $CName + ".txt") Dim ologfile $ologfile = fso.OpenTextFile($Logfile, 8, True) $ologfile.writeline ($DName + "\" + $UName) $ologfile.close End If End If
Sleep 7
Exit
|
|
Top
|
|
|
|
#120862 - 2004-06-08 08:15 PM
Re: VBSCRIPT converted to KIXTART (Set Statement)
|
ktodi
Getting the hang of it
Registered: 2002-03-29
Posts: 60
|
Still no go. I receive no errors and the script does not pause for 7 seconds so I know it is not completeing. I have fixed the "instr" command and taken the "Then" statements out. Any other ideas?
$w2kwxp = @PRODUCTTYPE = "Windows 2000 Professional" OR @PRODUCTTYPE = "Windows XP Professional"
If $w2kwxp Dim $WSHNetwork, $fso $WSHNetwork = CreateObject("WScript.Network") $fso = CreateObject("Scripting.FileSystemObject")
Dim $LogEntry $UName = @USERID $DName = @LDOMAIN $CName = @WKSTA
Dim $Status $Status = "NotLogged" If $fso.FileExists("\\nserv\wkslogs$\" + $CName + ".txt") Dim $SearchString $SearchString = ($DName + "\" + $UName) Dim $ParseFile, $TextStream, $TextLine $ParseFile = $fso.GetFile("\\nserv\wkslogs$\" + $CName + ".txt") $TextStream = $ParseFile.OpenAsTextStream While Not $TextStream.AtEndOfStream $TextLine = $TextStream.ReadLine If InStr($TextLine,$SearchString) <> 0 Status = "AlreadyLogged" End If Loop $TextStream.Close End If
If $Status = "NotLogged" Dim $Logfile $Logfile = ("\\nserv\wkslogs$\" + $CName + ".txt") Dim ologfile $ologfile = fso.OpenTextFile($Logfile, 8, True) $ologfile.writeline ($DName + "\" + $UName) $ologfile.close End If End If
Sleep 7
Exit
|
|
Top
|
|
|
|
#120863 - 2004-06-08 08:44 PM
Re: VBSCRIPT converted to KIXTART (Set Statement)
|
ktodi
Getting the hang of it
Registered: 2002-03-29
Posts: 60
|
Thanks you guys once again made my life easy, everything works now below is the working script.
$w2kwxp = @PRODUCTTYPE = "Windows 2000 Professional" OR @PRODUCTTYPE = "Windows XP Professional"
If $w2kwxp Dim $WSHNetwork, $fso $WSHNetwork = CreateObject("WScript.Network") $fso = CreateObject("Scripting.FileSystemObject")
Dim $LogEntry $UName = @USERID $DName = @LDOMAIN $CName = @WKSTA
Dim $Status $Status = "NotLogged" If $fso.FileExists("\\nserv\wkslogs$\" + $CName + ".txt") Dim $SearchString $SearchString = ($DName + "\" + $UName) Dim $ParseFile, $TextStream, $TextLine $ParseFile = $fso.GetFile("\\nserv\wkslogs$\" + $CName + ".txt") $TextStream = $ParseFile.OpenAsTextStream While Not $TextStream.AtEndOfStream $TextLine = $TextStream.ReadLine If InStr($TextLine,$SearchString) <> 0 $Status = "AlreadyLogged" EndIf Loop $TextStream.Close EndIf
If $Status = "NotLogged" Dim $Logfile $Logfile = ("\\nserv\wkslogs$\" + $CName + ".txt") Dim $ologfile $ologfile = $fso.OpenTextFile($Logfile, 8, True) $ologfile.writeline ($DName + "\" + $UName) $ologfile.close EndIf EndIf
Sleep 7
Exit
|
|
Top
|
|
|
|
#120869 - 2004-06-09 10:15 AM
Re: VBSCRIPT converted to KIXTART (Set Statement)
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
It works because it is perfectly correct syntax. There is nothing wrong with it at all.
You will see this syntax used frequently, and it is actually good programming style.
Quote:
but It's quite pointless as it results in any case true
No, for a Win9x or NT box the expression will of course evaluate to "0", which is what it required.
As a personal preference I'd use parentheses to highlight the sub-expressions and ensure correct parsing. I might also use the bitwise "|" but in fact the logical "OR" is more correct in this case: Code:
$w2kwxp = (@PRODUCTTYPE = "Windows 2000 Professional") | (@PRODUCTTYPE = "Windows XP Professional")
Other languages like 'C' have seperate assignment ('x=0') and equivalent ('if(x==0)') operators because it is not always possible to determine from context whether the expression is assignment or syntax.
This is a good example of how it can be ambiguous, but fortunately the KiXtart parser makes the right choice.
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 756 anonymous users online.
|
|
|