Running a Windows NT Task that Requires an Active Connection to NDS
Articles and Tips: tip
Albion College
dlupo@albion.edu
01 Feb 2002
I've recently had to run a vbs script on one of my servers nightly. This normally wouldn't be a problem, but since I don't like to leave myself logged in to the console on a Windows 2000 workstation when I'm not in front of it, I found that any time the script wanted to touch data on a Novell volume, it wouldn't be connected to the tree and it would then "bomb out."
So I wrote a little utility that would check to see if there was a valid connection to the tree. If there was not, the utility would make a connection, then it would run a task that you specify in a "todo.cmd" file. Once that was completed, the utility would clear the connection and exit.
I could then have the task scheduler run this application and have it access the NetWare volumes without being logged in. I found this to be kind of nice, so I thought I would share the code for anyone in a similar tight spot. (If you use or borrow any piece of the code though, I wouldn't mind hearing from you--use the e-mail address above.)
'autoLogin by Dave Lupo '12-13-01 'dlupo@albion.edu Option Explicit
Public varDone As Variant Public varTmp As Variant
Private Sub Form_Load() 'inits the form caption and the task completion status frmMain.Caption = "Waiting to connect" varDone = "no" End Sub
Private Sub Form_Unload(Cancel As Integer) varTmp =NWSess1.Logout("NDS:\\Tree\OrgName\OUName\OUsers\UserName") 'put your info here or use an ini file if you like to set this stuff End Sub
Private Sub Timer1_Timer() 'Timer should be set to 10,000 milliseconds Dim II As Integer Dim blnOn As Boolean Dim msg As Variant
On Error GoTo errH:
Timer1.Enabled = False errH: blnOn = False For II = 0 To NWSess1.ConnectedTrees.Count - 1 If NWSess1.ConnectedTrees.Item(II).FullName = "NDS:\\Tree" Then blnOn = True Next II
If blnOn = False Then frmMain.Caption = "Attempting to connect" NWSess1.RunScripts = True varTmp = NWSess1.Login("NDS:\\Tree", ".UserName.OUsers.OUName.OrgName", "password", False) If Not varTmp Then 'failed DoEvents GoTo errH: frmMain.Caption = "Not connected" Else 'connected frmMain.Caption = "Connected" End If Else msg = "" For II = 0 To NWSess1.ConnectedTrees.Count - 1 msg = msg & " " & NWSess1.ConnectedTrees.Item(II).ShortName Next II msg = Trim(msg) frmMain.Caption = "Connected to " & msg If varDone = "no" Then 'this section just tells us whether the task has been Timer2.Enabled = True 'run or not so we can either run it or disconnect Else varTmp = NWSess1.Logout("("NDS:\\Tree\OrgName\OUName\OUsers\UserName") End End If End If Timer1.Enabled = True End Sub
Public Function todo() As Variant 'Requires a todo.cmd file in the same directory as the application 'cmd files work a lot like batch files and can be made inside of notepad Dim filefinder As String filefinder = "" filefinder = Dir(App.Path & "\todo.cmd") If Len(Trim(filefinder)) > 1 Then todo = Shell(App.Path & "\todo.cmd") End If End Function
Private Sub Timer2_Timer() 'Timer should be set to 15,000 milliseconds 'I found having the second timer improves the pace at which the app runs Timer2.Enabled = False varDone = todo End Sub
* Originally published in Novell AppNotes
Disclaimer
The origin of this information may be internal or external to Novell. While Novell makes all reasonable efforts to verify this information, Novell does not make explicit or implied claims to its validity.