GreatWest Posted April 26, 2011 Posted April 26, 2011 I've written an AutoIt script that will create a vb script to create an OU in AD. The write works just fine creating the VB script. If I execute the VB script manually it works fine. If I try and execute the VB script with a Run command in AutoIt I get "The process cannot access the file because it is being used by another process". Following is the part of the code. $VB1ScriptFileName = $SiteNameNS & ".vbs" FileOpen($VB1ScriptFileName,2) FileWriteLine($VB1ScriptFileName, "Option Explicit") FileWriteLIne($VB1ScriptFileName, "Dim objRoot, objDomain, objOU") FileWriteLine($VB1ScriptFileName, "Dim strOUContainer") FileWriteLine($VB1ScriptFileName, "Dim intUser") FileWriteLine($VB1ScriptFileName, " ") FileWriteLine($VB1ScriptFileName, "' Section to bind to YOUR Active Directory.") FileWriteLine($VB1ScriptFileName, "Set objRoot = GetObject(" & """" & "[url="ldap://rootDSE"]LDAP://rootDSE[/url]" & """" & ")") FileWriteLine($VB1ScriptFileName, "objDomain = objRoot.Get(" & """" & "defaultNamingContext" & """" & ")") FileWriteLine($VB1ScriptFileName, "Set objDomain = GetObject(" & """" & "LDAP://" & """" & " & " & "" & "objDomain)") FileWriteLine($VB1ScriptFileName, " ") FileWriteLine($VB1ScriptFileName, "' Section to create the OU defined by strOUContainer") FileWriteLine($VB1ScriptFileName, "' Note .SetInfo") FileWriteLine($VB1ScriptFileName, "strOUContainer =" & """" & "OU=Inet" & $Corp & $SiteNameNS & ", OU=BusinessSharePoint, OU=Sharepoint, OU=Application Groups, OU=Security Groups, OU=Groups" & """" ) FileWriteLine($VB1ScriptFileName, " ") FileWriteLine($VB1ScriptFileName, "'On Error Resume next") FileWriteLine($VB1ScriptFileName, "Set objOU = objDomain.Create(" & """" & "organizationalUnit" & """" & ", strOUContainer)") FileWriteLine($VB1ScriptFileName, "objOU.Put " & """" & "Description" & """" & "," & """" & $OUSiteDescription & """") FileWriteLine($VB1ScriptFileName, "objOU.SetInfo") FileWriteLine($VB1ScriptFileName, " ") FileWriteLine($VB1ScriptFileName, "'WScript.Echo " & """" & "New OU created = " & """" & " & strOUContainer") FileWriteLine($VB1ScriptFileName, "WScript.quit") FileClose($VB1ScriptFileName) EndFunc Func VBExecute() Run('wscript.exe "C:\Users\jjones\Documents\FileAu~1\"' & $VB1ScriptFileName,'',@SW_HIDE) EndFunc I thought that since I closed the file that this should work. Instead, I have to exit the AutoIt script completely before the file is released and I can run it. Can I run the file after creating and closing it? What am I missing here? Thanks for any help you can provide. Todd
AdmiralAlkex Posted April 26, 2011 Posted April 26, 2011 But that code doesn't close any file. FileClose() takes the filehandle returned by FileOpen(), not a filename. See helpfile. Also not using the handle in FileWriteLine() makes in kinda pointless to open the file. Don't mix handles and filenames for the same file. .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface
hannes08 Posted April 26, 2011 Posted April 26, 2011 Also you might consider to take a look at the by Water, which is, in my opinion, a great deal when handling AD specific work. Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]
FMS Posted April 26, 2011 Posted April 26, 2011 also i'm thinking of a DOS input from "dsadd" is much simpler instead of making a script to make a script to add a group in AD???? as finishing touch god created the dutch
GreatWest Posted April 28, 2011 Author Posted April 28, 2011 Thanks for the hint. I went back and looked at the help file again to see if I could figure out exactly what you were referring to. I see how I used the filename incorrectly and that's why the file doesn't close. Thanks for the tip. I'll play around when I have some time and see if I can get the process to work the way I need it to.ToddBut that code doesn't close any file. FileClose() takes the filehandle returned by FileOpen(), not a filename. See helpfile.Also not using the handle in FileWriteLine() makes in kinda pointless to open the file. Don't mix handles and filenames for the same file.
GreatWest Posted April 28, 2011 Author Posted April 28, 2011 I'll take a look but the script is also used by another process out of my control and not of my design. Maybe I can work something out with the designer of the system. I'm pretty much just developing a GUI for their process because it's all text based through PowerShell, some VB scripts and going directly in AD with AD users and computers. Kind of a hodge podge of stuff I'm working with, trying to build a GUI to do all the work instead of having to bounce all over the place. Thanks,ToddAlso you might consider to take a look at the by Water, which is, in my opinion, a great deal when handling AD specific work.
GreatWest Posted April 28, 2011 Author Posted April 28, 2011 Like I posted to Hanns, it's not my package or process. I'm just trying to make a GUI to do all the work that they have me manually doing by jumping all over the place. It's no bother to them, they don't have to do anything but test their procedure. I have to run their process several times a day and it's a real joy. Thanks,Toddalso i'm thinking of a DOS input from "dsadd" is much simpler instead of making a script to make a script to add a group in AD????
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