Problem when running Access with Admin privilege by ShellExecute (1 Viewer)

Babycat

Member
Local time
Today, 22:53
Joined
Mar 31, 2020
Messages
281
Hi all

I have a VBS file to run Access app. My Access app writes few values to registry under HKEY_LOCAL_MACHINE, thus it is required to run with Admin privilege.
My PC has only one account: Admin, no passwword and i am using this account. However I still have to use argument "runas" as below code. This make me a bit confused...
Here is my VBS code:
Code:
        ' Run the command with ShellExecute
        objShellA.ShellExecute """" & accessApp & """" , """" & FEPath & """", "", "runas", 1
        ' objShellA.ShellExecute """" & accessApp & """" , """" & FEPath & """", "", "open", 1

1727432425305.jpeg


And, the true problem is: When running with "runas" (admin privilege), I can't type unicode characters for my local language (Vietnamese) in any controls of Access.
It does not happen when i use argument "open", meaning I can type Vietnamese language into controls but now my Access app can not write to HKEY_LOCAL_MACHINE registry.

ChatGPT hints me about the enviroment variable things, the input language may be changed when I use "runas"...
I am still strugglling in this mess and no solution yet.

Is there any one experienced with this problem?
Or any suggestion please.

Thank you
 
Last edited:
can you try and test this script:
Code:
' by Chatgpt
Dim objAccess
Dim FEPath

' Set the path to your Access database
' replace the path with the path of your FE
FEPath= "C:\Users\Administrator\documents\search_formn.accdb"

' Create an instance of MS Access
Set objAccess = CreateObject("Access.Application")

' Open the Access database
objAccess.OpenCurrentDatabase FEPath

' Make MS Access visible (keep it open)
objAccess.Visible = True

' Keep script running to keep Access open
Do While objAccess.CurrentProject Is Nothing = False
    WScript.Sleep 100
Loop
 
can you try and test this script:
Code:
' by Chatgpt
....
' Keep script running to keep Access open
Do While objAccess.CurrentProject Is Nothing = False
    WScript.Sleep 100
Loop

Hi Arnelgp.
First of all: It works
What did you ask ChatGPT?
I am not sure why keeping "script running to keep Access open" could solve the problem...
 
Furthermore, when I quit Access, VBS prompts this error:

1727435313554.png
 
try changing this line to:
Code:
objAccess.OpenCurrentDatabase "" & FEPath & ""
 
My PC has only one account: Admin, no passwword and i am using this account.

Not true. You just don't see the other accounts. One of them is SYSTEM, which has different permissions than Admin. A "RunAs" allows you to assure that you aren't running as one of the default (hidden) accounts.
 
If the code works and the only issue is after you close Access, you could try:

Code:
' Keep script running to keep Access open
On error Resume Next
Do While objAccess.CurrentProject Is Nothing = False
    WScript.Sleep 100
Loop
Quit

It's sloppy but I do not know of another way to exit gracefully and since the task is completed, there is really no need to.
 
Not true. You just don't see the other accounts. One of them is SYSTEM, which has different permissions than Admin. A "RunAs" allows you to assure that you aren't running as one of the default (hidden) accounts.
Yeah, indeed I only see one account named Admin.
 
If the code works and the only issue is after you close Access, you could try:

Code:
' Keep script running to keep Access open
On error Resume Next
Do While objAccess.CurrentProject Is Nothing = False
    WScript.Sleep 100
Loop
Quit

It's sloppy but I do not know of another way to exit gracefully and since the task is completed, there is really no need to.
It works.
The script quits without throwing an error msg to user. I think that is fine
 
Yeah, indeed I only see one account named Admin.

MS does that because if you tried to create an account with one of the "special" names, you get tossed out. These are names used by the network and domain software. They show up more often on the Win Pro versions rather than the Win Home versions, and they are DEFINITELY in evidence if you have a Win Server version.
 

Users who are viewing this thread

Back
Top Bottom