#132371 - 2005-01-14 11:37 PM
Re: Lexer for KiX
|
Allen
KiX Supporter
   
Registered: 2003-04-19
Posts: 4562
Loc: USA
|
Hey Jim, thought I would pass this along to you (as well as a few asprin ) :
Microsoft has a daily article on "Howto" in VBS, called Hey, Scripting Guy! and the archives may help you in your quest.
As a side note, a few weeks back, we were discussing how complicated just mapping a drive was in VBS compared to KIX, and I made an attempt to convert their code into a function. It's untested, but may get you going if you haven't done that conversion yet.
Good Luck!
|
|
Top
|
|
|
|
#132372 - 2005-01-14 11:58 PM
Re: Lexer for KiX
|
jtokach
Seasoned Scripter
   
Registered: 2001-11-15
Posts: 513
Loc: PA, USA
|
Alpo, I try to keep up with the boards and did spot this article and I did incorporate it into the library already! Thanks for saving me time!
Quote:
Microsoft has a daily article on "Howto" in VBS, called Hey, Scripting Guy! and the archives may help you in your quest.
I'm also all over this. I sent this message to them on Thursday. Note you'll recognize a converted CError() udf. Quote:
I'm probably not alone here by saying VBScript's error handling has me frustrated. Particularly, COM errors that vbscript doesn't seem to be able to interpret. For instance, if I run this code snippet: On Error Resume Next Set objGroup = GetObject("WinNT://"& strComputer &"/"& strLocalDestinationGroup) objGroup.Add "WinNT://"& strUserToAdd wscript.echo err.number wscript.echo err.description and it fails because the user I'm trying to add already belongs to the target group, the err returned is: -2147023518 and the descriiption is empty. Therein lies the problem. HOWEVER, if I remove the On Error Resume Next, the compiler quits execution on the .Add method and correctly resolves the error to: User is already a member of the target group. So I'm using this function to convert the error to hex and back again into a standard System Error Code. Function CError(lErr) If lErr<0 Then lErr=HexToDec(Right(Hex(lErr),4)) End If Err.Number = lErr End function
Function HexToDec(strHex) dim lngResult dim intIndex dim strDigit dim intDigit dim intValue lngResult = 0 for intIndex = len(strHex) to 1 step -1 strDigit = mid(strHex, intIndex, 1) intDigit = instr("0123456789ABCDEF", ucase(strDigit))-1 if intDigit >= 0 then intValue = intDigit * (16 ^ (len(strHex)-intIndex)) lngResult = lngResult + intValue else lngResult = 0 intIndex = 0 ' stop the loop end if next HexToDec = lngResult End Function Now, CError will properly convert -2147023518 to decimal 1378 which we can verify on this table: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/debug/base/system_error_codes__1300-1699_.asp
The problem is this. If I try to err.raise= 1378, VBScript is clueless. Setting err.number = 1378 does help either. How can I get VBScript to recognize and resolve these standard error codes to the proper description? Any other error handling methodologies would be great help as well.
_________________________
-Jim
...the sort of general malaise that only the genius possess and the insane lament.
|
|
Top
|
|
|
|
#132373 - 2005-01-19 04:29 AM
Re: Lexer for KiX
|
Allen
KiX Supporter
   
Registered: 2003-04-19
Posts: 4562
Loc: USA
|
Hey Jim... I worked over the Cerror function... tell me what you think.
Code:
on error resume next
strComputer="computer"
strLocalDestinationGroup="Administrators"
strUsertoAdd="Administrator"
Set objGroup = GetObject("WinNT://"& strComputer &"/"& strLocalDestinationGroup)
objGroup.Add "WinNT://"& strUserToAdd
cerror(err.number)
wscript.echo err.number
wscript.echo err.description
Function CError(lErr)
dim cerr,ws,temp,cerrorfile,ret,fs,file,output
If lErr<0 Then
cErr=HexToDec(Right(Hex(lErr),4))
Set ws=Wscript.createobject("Wscript.Shell")
temp=ws.expandenvironmentStrings("%temp%")
cerrorfile=temp & "\cerror.txt"
ret=ws.run ("%comspec% /c net helpmsg " & cerr & " >" & CerrorFile,0,"True")
set fs=wscript.createobject("Scripting.FilesystemObject")
Set File=fs.OpenTextFile(cerrorfile,1)
file.skipline
output=file.readline
file.close
err.raise cerr,,output
End If
End function
Function HexToDec(strHex)
dim lngResult
dim intIndex
dim strDigit
dim intDigit
dim intValue
lngResult = 0
for intIndex = len(strHex) to 1 step -1
strDigit = mid(strHex, intIndex, 1)
intDigit = instr("0123456789ABCDEF", ucase(strDigit))-1
if intDigit >= 0 then
intValue = intDigit * (16 ^ (len(strHex)-intIndex))
lngResult = lngResult + intValue
else
lngResult = 0
intIndex = 0 ' stop the loop
end if
next
HexToDec = lngResult
End Function
|
|
Top
|
|
|
|
#132375 - 2005-01-20 10:30 PM
Re: Lexer for KiX
|
Allen
KiX Supporter
   
Registered: 2003-04-19
Posts: 4562
Loc: USA
|
Great. While I was writing this, I was thinking, "It sure would be nice to have Pipe Function here." 
Anyway, I am mildly interested in your project. Even though this is VBScript (blasphemy in these parts), please keep the board informed and maybe share some of your code.
|
|
Top
|
|
|
|
#132377 - 2005-01-21 05:11 AM
Re: Lexer for KiX
|
Allen
KiX Supporter
   
Registered: 2003-04-19
Posts: 4562
Loc: USA
|
I have no idea what you are talking about. 
I'm not familiar CVS... care to elaborate?
|
|
Top
|
|
|
|
#132378 - 2005-01-21 06:13 AM
Re: Lexer for KiX
|
jtokach
Seasoned Scripter
   
Registered: 2001-11-15
Posts: 513
Loc: PA, USA
|
Ahh... Concurrent Versions System . Here's more than you want to know about CVS at sourceforge. On the short, it enables several users to write code on their local systems simultaneously and maintains every version of every file ever checked in. For instance, both of us check out a bunch of the same files, update them and create new ones. When we've made significant progress or were done working for the time being, we check in our files. If the other developers have already checked in, a diff program will display the differences and allow us to overwrite, merge, discard, etc.. You may have heard of Merant's PVCS or Microsoft's Visual Source Safe. Both commercial products provide similar features. CVS is opensource and generally included with every version of Unix or Linux that I can think of.
Sourceforge offers CVS services for its hosted projects. Both developers and non-developers can get all of the source code for every project available on sourceforge through CVS. Developers compile or in my case collect all of their source into a binary distributable (zip,tar,exe) and then make that available for download which is known as a release. Don't let me dumb it down though. Volumes have been written and published on it.
Sourceforge allows anyone to view the cvs for each project through the web without installing a client. The problem here is that these pages are not dynamic and seem to be updated on and inconsistent basis. Additionally, the client allows you to download the whole ball of wax whereas the web is one at a time.
Edited by jtokach (2005-01-21 06:20 AM)
_________________________
-Jim
...the sort of general malaise that only the genius possess and the insane lament.
|
|
Top
|
|
|
|
#132381 - 2005-01-21 07:48 AM
Re: Lexer for KiX
|
Allen
KiX Supporter
   
Registered: 2003-04-19
Posts: 4562
Loc: USA
|
Okay... I'm trying to pull myself away from this... hopefully this will be the last...
I hacked on Chris's WSHPipe and it functions pretty close to his original. You may have to revist exit codes in it, but for now, it works.
Code:
on error resume next
strComputer="computer"
strLocalDestinationGroup="Administrators"
strUsertoAdd="Administrator"
Set objGroup = GetObject("WinNT://"& strComputer &"/"& strLocalDestinationGroup)
objGroup.Add "WinNT://"& strUserToAdd
cerror(err.number)
wscript.echo err.number
wscript.echo err.description
function display
Msgbox Err.number & ":" & Err.Description
Err.clear
end function
Function CError(lErr)
dim cerr,output,line,errdesc
If lErr<0 Then
cErr=HexToDec(Right(Hex(lErr),4))
output=wshpipe("net helpmsg " & cerr)
for each line in output
if line<>"" then
errdesc=errdesc & " " & line
end if
next
errdesc=ltrim(errdesc)
Err.raise cerr,,errdesc
End If
End function
Function WshPipe(ShellCMD)
Dim oExec, Output, ExitCode
Set oExec = CreateObject("WScript.Shell").Exec(ShellCMD)
If Not VarType(oExec)=9 then
WshPipe="WScript.Shell Exec Unsupported"
Err.Raise 10
Exit Function
End If
Output = oExec.StdOut.ReadAll & oExec.StdErr.ReadAll
WshPipe=Split(Join(Split(Output,CHR(13)),""),CHR(10))
End Function
Function HexToDec(strHex)
dim lngResult
dim intIndex
dim strDigit
dim intDigit
dim intValue
lngResult = 0
for intIndex = len(strHex) to 1 step -1
strDigit = mid(strHex, intIndex, 1)
intDigit = instr("0123456789ABCDEF", ucase(strDigit))-1
if intDigit >= 0 then
intValue = intDigit * (16 ^ (len(strHex)-intIndex))
lngResult = lngResult + intValue
else
lngResult = 0
intIndex = 0 ' stop the loop
end if
next
HexToDec = lngResult
End Function
|
|
Top
|
|
|
|
Moderator: Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart
|
1 registered
(Allen)
and 1198 anonymous users online.
|
|
|