• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 595
  • Last Modified:

How can I use NT Authentication using VBSCRIPT?

Hello Everyone,

I have a script that creates, reads and delete a file from our network drive. I wrote this script to see if I can find out what user can't access our network drive on any given reason. I have been having trouble with some users losing their network permissions off and on this past few days.

What I'm hoping to do is have the vbscript run as the user(s) and see if the user's network permission is in good standing or not.

How can I get the below script to run as a particular user? P.S. we use AD as our NT Authentication. Thank you
'**********************************************************************
'  Visual Basic ActiveX Script
'************************************************************************
 
Function Main()
 
'Step #1 - Delete file if already exist
Set objFSO = CreateObject("Scripting.FileSystemObject")
IF objFSO.FileExists("\\Jcnas01\cms\CMSOPEN\NagiosAccess.txt")Then
objFSO.DeleteFile("\\Jcnas01\cms\CMSOPEN\NagiosAccess.txt")
End If
 
dtEndDate=DateAdd("s", 3, Now)
   while Now < dtEndDate
'waiting for file deletion to finish
   wend
 
'Step #2 - Create text file 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile("\\Jcnas01\cms\CMSOPEN\NagiosAccess.txt")
 
dtEndDate=DateAdd("s", 3, Now)
   while Now < dtEndDate
'waiting for file creation to finish
   wend
 
	Main =DTSTaskExecResult_Success
End Function
 
'Step #3 - Read text file 
Function Main()
Const ForAppending = 8
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
    ("\\Jcnas01\cms\CMSOPEN\NagiosAccess.txt", ForAppending, True)
Set colServices =  GetObject("winmgmts:").ExecQuery _
    ("Select * from Win32_Service")
For Each objService in colServices    
    objTextFile.WriteLine(objService.DisplayName & vbTab & _
        objService.State)
Next
objTextFile.Close
	Main =DTSTaskExecResult_Success
End Function

Open in new window

0
redouard
Asked:
redouard
  • 5
  • 2
1 Solution
 
nmcdermaidCommented:
So you are running this in DTS?
I suggest you run it as a standalone VBS script (not inside DTS) and schedule to run everyday using the RUNAS command.
I started converting it to standalone VBScript, but you have two Function Mains(). Why is that?
In actual fact you could run just a DOS command script to try creating a file on a share under different credentials. I strongly suggest you add this to the DOS/Batch Scripting Zone!
0
 
redouardAuthor Commented:
Hello,

I made the changes you recommended but now when I run the following command nothing happens

C:\>RUNAS /profile /user:ad\XXXX "CScript.exe \"c:\scriptname.vbs"\"

What am I doing wrong?
0
 
nmcdermaidCommented:
Did you work out why you have two Mains in it? I suggest you also add
 
msgbox "complete"
 
to the end of the code just to tell it finished running.
Lastly... did it actually create the text file?
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
redouardAuthor Commented:
I modified the script to have only one Function Main. Here's the modified vbs code:

'**********************************************************************
'  Visual Basic ActiveX Script
'************************************************************************
Function Main()

'Step #1 - Delete file if already exist
Set objFSO = CreateObject("Scripting.FileSystemObject")
IF objFSO.FileExists("\\Jcnas01\cms\CMSOPEN\NagiosAccess.txt")Then
objFSO.DeleteFile("\\Jcnas01\cms\CMSOPEN\NagiosAccess.txt")
End If
 
dtEndDate=DateAdd("s", 6, Now)
   while Now < dtEndDate
'waiting for file deletion to finish
   wend
       Main =DTSTaskExecResult_Success
End Function

and no it did not create a file.
0
 
nmcdermaidCommented:
OK, I've now converted that code from VBS that runs inside DTS to VBS that runs outside DTS.
 
Basically you have to explicitly call Main.

Call Main()
 
Sub Main()
 
'Step #1 - Delete file if already exist
Set objFSO = CreateObject("Scripting.FileSystemObject")
IF objFSO.FileExists("\\Jcnas01\cms\CMSOPEN\NagiosAccess.txt")Then
objFSO.DeleteFile("\\Jcnas01\cms\CMSOPEN\NagiosAccess.txt")
End If
 
dtEndDate=DateAdd("s", 6, Now)
   while Now < dtEndDate
'waiting for file deletion to finish
   wend
 
 
msgbox "Finished"
 
End Function

Open in new window

0
 
nmcdermaidCommented:
Version 2.... this one is more likley to run without an error. Please disregard prior post.
Call Main()
 
Sub Main()
 
'Step #1 - Delete file if already exist
Set objFSO = CreateObject("Scripting.FileSystemObject")
IF objFSO.FileExists("\\Jcnas01\cms\CMSOPEN\NagiosAccess.txt")Then
objFSO.DeleteFile("\\Jcnas01\cms\CMSOPEN\NagiosAccess.txt")
End If
 
dtEndDate=DateAdd("s", 6, Now)
   while Now < dtEndDate
'waiting for file deletion to finish
   wend
 
 
msgbox "Finished"
 
End Sub

Open in new window

0
 
nmcdermaidCommented:
.... oh and as you are running it as another user, the msgbox may not appear.
I suggest you remove the msgbox line as I recall you will be running this a scheduled batch process.
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now