Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

.Bat tu run myapp.exe as amministrator 1

sal21

Programmer
Apr 26, 2004
432
IT
In c:\mydir\app.exe
Ho to create .Bat, in the same dir, to run app exe as admistrator?
In vb6 please.
 
You'll need to clarify. Are you simply hoping there is a batch script that'll run your app under the built-in admin account? Or simply run with admin rights? Are you hoping to avoid any user interaction (i.e UAC )? Do you always want it opened this way? Please just list your actual requirements. Why do you require admin rights in the first place?
 
Last edited:
Or simply run with admin rights! yes
Do you always want it opened this way! yes
 
Well, you don't need a bat file then (which is lucky since the various bat file solutions for promoting access rights are generally convoluted and a pain).

Yopu can do it in VB6 with a manifest file, which is a little advertised feature, except for to those wanting old VB6 programs to stop looking like they are running on XP and instead look like they are running on a current OS - i.e your VB6 program can adopt current OS visual styles for all the common controls. But that is not their only use.

So, simply copy and paste the following into a new text file:

Code:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
   <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
      <security>
         <requestedPrivileges>
            <requestedExecutionLevel
               level="requireAdministrator"
               uiAccess="False"/>
         </requestedPrivileges>
      </security>
   </trustInfo>
</assembly>

Then rename it as myprojectname.exe.manifest, and distribute it with your application; it needs to be in the same folder as the application itself.

So if your project is called Sal21sBigApp and compiles to a program called Sal21sBigApp.exe, then the manifest file should be called Sal21sBigApp.exe.manifest

And that's all yo0u need to do.

Note that it is possible to embed the manifest (as a resource) into your VB6 app itself, thus avoiding the need to deploy it as a separate file (which is still fairly easy if you are using a decent deployment toolkit). However it isn't straightforward, since VB6's built-in resource editor/compiler doesn't know how to create a manifest resource. So you need a tool to compile your manifest into a resource file first, and then load that resource file into VB6. I'm not going to go into the details of that, although I will attach a precompiled resource file of the manifest above which you can play with if you want (remove the .txt extension - and do not try and edit it, particularly in a simple text editor)
 

Attachments

  • Manifest_1.res.txt
    504 bytes · Views: 1

Part and Inventory Search

Sponsor

Back
Top