Sign in to follow this  
Followers 0
fisofo

RunAsSet and quickbooks

8 posts in this topic

Here's an interesting one. You may know that quickbooks can only be run as an admin or a power user... well i'm trying to get quickbooks to run from a restricted user account. Now, it's easy enough to make a shortcut that runs the app as an administrator, what I would like to be able to do though is have the script be able to open files as an admin as well.

So basically, the file type of *.qbw is set to open with quickbooks currently, is there a way to tell it to open the file with my script, and then have the script run quickbooks as an admin and open the file the user is trying to open? Does that make sense?

let me know what ya think!

Share this post


Link to post
Share on other sites



hmmm I think I know what you mean (double click the file document and have it run your script which runs the program as admin right?!).. i've been thinking about how to do this for something else as well.

Could you modify the Edit action for Type (for your .qbs file) which is under Folder Options > File Types > filetypeinquestion > Advanced Button > Action you want to change > Edit Button .

What I was thinking was you could change that from whatever it is currently is and point it to the path of your script, and then from within your script tell it to run Quickbooks (as admin) with whatever file path is passed to the script (unsure of this part, looking at other file types it looks like %1 seems to be the path of the file given to other programs, pretty sure this could be grabbed from AutoIt using the normal command line methods).

If i get a chance I'll have a play with it... although there may be easier ways which I'm sure someone will point out if there are.

Share this post


Link to post
Share on other sites

Information is kept at HKEY_CLASSES_ROOT of the registry. Remember to always use full path on the file values.

RegWrite ("HKEY_CLASSES_ROOT\.qbw", "", "REG_SZ", "QuickBook_CustomFile")
RegWrite ("HKEY_CLASSES_ROOT\QuickBook_CustomFile\DefaultIcon", "", "REG_SZ", $MyIconFile)
RegWrite ("HKEY_CLASSES_ROOT\QuickBook_CustomFile\shell\open\command", "", "REG_SZ", $MyScriptFile)

[quote name='Valik' post='301213' date='Jan 31 2007, 10:36 PM']You seem to have a habit of putting things in the wrong place. I feel sorry for any female you attempt to have sex with.[/quote][font="Lucida Sans Unicode"][/font]

Share this post


Link to post
Share on other sites

Could you modify the Edit action for Type (for your .qbs file) which is under Folder Options > File Types > filetypeinquestion > Advanced Button > Action you want to change > Edit Button .

Yeah, I had thought of something like that, but wasn't sure if the file path would get passed or not... i guess i'll need to try that, let me know if you have any success :P

Information is kept at HKEY_CLASSES_ROOT of the registry. Remember to always use full path on the file values.

RegWrite ("HKEY_CLASSES_ROOT\.qbw", "", "REG_SZ", "QuickBook_CustomFile")
RegWrite ("HKEY_CLASSES_ROOT\QuickBook_CustomFile\DefaultIcon", "", "REG_SZ", $MyIconFile)
RegWrite ("HKEY_CLASSES_ROOT\QuickBook_CustomFile\shell\open\command", "", "REG_SZ", $MyScriptFile)
Thanks Coe... although I'm still unsure as to how to get the file path, does it get passed automatically? And is what you posted bascially the same as editing file type info? I wasn't sure what I was looking at...

thanks for the input guys!

Share this post


Link to post
Share on other sites

Yes it is. Just check these keys using the registry editor and you'll understand what I mean with full path.


[quote name='Valik' post='301213' date='Jan 31 2007, 10:36 PM']You seem to have a habit of putting things in the wrong place. I feel sorry for any female you attempt to have sex with.[/quote][font="Lucida Sans Unicode"][/font]

Share this post


Link to post
Share on other sites

Yes it is. Just check these keys using the registry editor and you'll understand what I mean with full path.

gotcha... you rock!

I'll post some code in the next few days (bit busy right now) once I figure this out.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Hey mate,

Had a quick play with it and had a bit of luck. The following code runs notepad as administrator and opens the correct file path (if there is one).

;sets the admin password stuff
RunAsSet("Administrator", @ComputerName, "Password")

;runs notepad with the filename specified (get's this from %1 in the file type windows settings stuff), appropriate working directory will also need to be set
If $CmdLine[0] > 0 Then
    Run("C:\WINDOWS\NOTEPAD.EXE" & " " & $CmdLine[1], "C:\temp") ;$CmdLine[1] is the path to the file that was double clicked in Windows
Else ;if no filepath given (there should be) just opens notepad
    Run("C:\WINDOWS\NOTEPAD.EXE", "C:\temp")
EndIf

Way i tested it was using CoePSX's example above created a new key (.test) at the root of HKEY_CLASSES_ROOT. Modify the default value to have the name of your choice (i used AdminTest). Then create the following Key Structure starting at the root of HKEY_CLASSES_ROOT > AdminTest (or the name you chose)\shell\open\command & then modify the value of default to "C:\AdminTest.exe" "%1" . Now if you create a text document with some dummy text in it > Save it and rename the file to end in .test the next time you double click on it (assuming you've got your compiled script at the place you just specified with the right admin details) it should spawn a notepad instance (started under the Admin account > can check task manager to be sure) with the file opened :D .

I think it should be relatively the same process to pass a file to Quickbooks (i dont use it though). See if Quickbooks will let you open a file by doing a Start > Run > C:\quickbooks.exe "c:\testfile.qbs" . :P

Edited by fu2m8

Share this post


Link to post
Share on other sites

Hey mate,

Had a quick play with it and had a bit of luck. The following code runs notepad as administrator and opens the correct file path (if there is one).

;sets the admin password stuff
RunAsSet("Administrator", @ComputerName, "Password")

;runs notepad with the filename specified (get's this from %1 in the file type windows settings stuff), appropriate working directory will also need to be set
If $CmdLine[0] > 0 Then
    Run("C:\WINDOWS\NOTEPAD.EXE" & " " & $CmdLine[1], "C:\temp") ;$CmdLine[1] is the path to the file that was double clicked in Windows
Else ;if no filepath given (there should be) just opens notepad
    Run("C:\WINDOWS\NOTEPAD.EXE", "C:\temp")
EndIf

Way i tested it was using CoePSX's example above created a new key (.test) at the root of HKEY_CLASSES_ROOT. Modify the default value to have the name of your choice (i used AdminTest). Then create the following Key Structure starting at the root of HKEY_CLASSES_ROOT > AdminTest (or the name you chose)\shell\open\command & then modify the value of default to "C:\AdminTest.exe" "%1" . Now if you create a text document with some dummy text in it > Save it and rename the file to end in .test the next time you double click on it (assuming you've got your compiled script at the place you just specified with the right admin details) it should spawn a notepad instance (started under the Admin account > can check task manager to be sure) with the file opened :D .

I think it should be relatively the same process to pass a file to Quickbooks (i dont use it though). See if Quickbooks will let you open a file by doing a Start > Run > C:\quickbooks.exe "c:\testfile.qbs" . :P

Man, I need to get back into the "groove" in coding... I just haven't been motivated lately to really focus. I blame a really busy work schedule :)

Anyway, that's awesome! I'll need to be putting this in for a client soon, so i'll update with how it works. Thank you!

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0