DBusse Posted February 25, 2008 Posted February 25, 2008 Let me start my first post by saying how much I love AutoIt! I've only been trying it for a short time, but it's already proven itself so well that I'm in the process of converting all of our current scripting from WinBatch (slow, clunky, resource-intensive, and $$$) over to AutoIt. Most of the scripting is translating well, and we're seeing a big performance boost for every task I've converted so far. The forums have been a big help to that end -- maybe a little too much, as I have about a million ideas running around my head to try out. I'm posting because I've hit a spot in converting that I can't seem to figure out an AutoIt alternative for our old script. One of our existing scripts uses a NetWare extender in WinBatch to see if a certain file is open on the server, and who has it open. It then alerts the user they need to close the file through GroupWise Messenger, and skips running the software that would update that file. I've found scripting that lets you know if the file is in use, but nothing on being able to identify who has the file open. Does anyone else have a solution to this that they could recommend? I'm not really much of an expert on NetWare, as my competency level is just high enough to deal with basic maintenance. I'd really like to keep this process "as-is", as the alternative is to have the script message me and my boss. We're both often away from our desks dealing with other problems, or busy enough that intervening isn't a priority. This is the code I'm using to check for the file being in use that I found elsewhere in the forums, with a few comments added: $MyFile = "F:\netware_drive\some_path\to_reports\file_everyone_leaves_open.pdf" If _FileTestOpen($MyFile) Then ; This will be modified to run the external program that generates the report, then print the PDF MsgBox(64, "File", "File can be used.") Else ; This will be modified to use Internet Explorer to create the message to the end user ; It also skips executing the update MsgBox(16, "File", "Error. Can not use file: @error = " & @error) EndIf Func _FileTestOpen($FileIn) If Not FileExists($FileIn) Then Return SetError(1, 0, 0) Local $hFile = FileOpen($FileIn, 1) If $hFile = -1 Then Return SetError(2, 0, 0) Else FileClose($hFile) Return 1 EndIf EndFunc ;==>_FileTestOpen Thanks!
rudi Posted February 25, 2008 Posted February 25, 2008 (edited) Hi.use "autoit" instead of "code" for autoit scripts:$MyFile = "F:\netware_drive\some_path\to_reports\file_everyone_leaves_open.pdf" If _FileTestOpen($MyFile) Then ; This will be modified to run the external program that generates the report, then print the PDF MsgBox(64, "File", "File can be used.") Else ; This will be modified to use Internet Explorer to create the message to the end user ; It also skips executing the update MsgBox(16, "File", "Error. Can not use file: @error = " & @error) EndIf Func _FileTestOpen($FileIn) If Not FileExists($FileIn) Then Return SetError(1, 0, 0) Local $hFile = FileOpen($FileIn, 1) If $hFile = -1 Then Return SetError(2, 0, 0) Else FileClose($hFile) Return 1 EndIf EndFunc ;==>_FileTestOpenI'd recommend to ask in the Novell Support Forums, News Server = news://forums.novell.com/ or if you prefer http it's here: http://forums.novell.com/novell-product-support-forums/Groups, that might be the right ones are the client forum and the netware admin forum. Ask if it's possible to (ab)use NCP APIs or client DLLs for your purpose.Don't miss to give there these information to the group:What NetWare version / SP version are you talking about? IP/IPX? TFS/NSS?MS Client for NetWare or Novell Client for Netware? Version?Good luck, regards, Rudi. Edited February 25, 2008 by rudi Earth is flat, pigs can fly, and Nuclear Power is SAFE!
DBusse Posted March 11, 2008 Author Posted March 11, 2008 Thanks for the response rudi, and sorry for the first-timer mistakes. I'll try to avoid any more mistakes. If anyone else is interested in this sort of thing, you *can* get the sofware development kit from Novell off their website if you have a user account there. (So I'm not sure if it's freely available, but it should be if you have an active support contract with them.) I've even managed to figure out SOME of the scripting, but I've hit a wall. Bear in mind I'm not exactly a top-notch programmer... expandcollapse popup; Test script: Check to see if a user has a file open, and if so, who is it so we know which user needs to be forced out. ; Create variable for later use Dim $result Dim $connresult ; Open the file we're checking so we have a file handle to give the DLL $fresult = FileOpen("F:\some\netware\path\openfile.pdf",0) ; If something goes wrong with the file, make sure it's closed and get out If $fresult = -1 Then FileClose($fresult) Exit(1) EndIf ; Open the DLL. Calwin32 is installed to the sys32 folder by the NW Client $dll = DllOpen("C:\WINDOWS\SYSTEM32\calwin32.dll") ; Call the DLL. We should be given back a handle to the connection ID using the file ; This is where it is currently crashing. Comment this line out and the script runs fine. $framejob = DllCall($dll, "ptr", "NWGetFileConnectionID", "ptr", $fresult, "ptr", $result) If @error = 1 Then MsgBox(0,"Output","Couldn't use DLL.") If @error = 2 Then MsgBox(0,"Output","Unknown return type.") If @error = 3 Then MsgBox(0,"Output","Function not found") DllClose($dll) ; Framejob[0] is the pointer to a connection $dll = DllOpen("C:\WINDOWS\SYSTEM32\clxwin32.dll") ; connhandle, infotype to return, length of buffer to return, pointer to buffer for returned info $connjob = DllCall($dll, "ptr", "NWCCGetConnInfo", "ptr", $framejob[0], "int", 5, "int", 32, "ptr", $connresult) If @error = 1 Then MsgBox(0,"Output","Couldn't use DLL.") If @error = 2 Then MsgBox(0,"Output","Unknown return type.") If @error = 3 Then MsgBox(0,"Output","Function not found") If $connjob[0] = "0x0000880E" Then MsgBox(0,"Output","Buffer too small") ; Close the file and DLLs. DllClose($dll) FileClose($fresult) MsgBox(0,"Output",$connjob[0]) ; Once we have some actual data to work with, we'll worry about plugging in output or passing it on to the calling script/function. Everything seems to run fine up to the DllCall for NWCCGetConnInfo part. At ' "int", 32 ', it's expecting to be given a buffer size. All the documentation tells me is that the minimum buffer sice is nuint32, which is meaningless to me beyond knowing it's some wierd C++ data type. No value I've put here has been large enough, and omitting the value causes the script to crash and burn. (Hence the check for the 880E return value, as I *should* be getting a plain integer.) Of course, I'm not sure I'm even giving it the right function "infotype" parameter to run, which determines the information to be returned. Again, the documentation is C++ based, and just suggests me "0x0005" and "NWCC_INFO_USER_ID" for values; I'm assuming the "5" in there works fine, as passing the hex string threw the function not found error trap. My guess is I need help in converting whatever information it's expecting from C++ to whatever AutoIt passes to the DLL. Any suggestions? I feel I'm almost on the edge of having this problem dealt with... If it matters: WinXP SP2, Novell Client 4.90 SP2, and the server's NetWare 6.5 SP 6.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now