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 Chris Miller 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
450
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: 3
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)
It would be complicated when there are other resources in program. Manifest file is recommended. Or, how about set administrator right in a install tools?
 
>Manifest file is recommended

By whom? I'd wager that sal21 isn't currently using a resource file, so the complication you mention doesn't really exist. Using a separate manifest or an embedded manifest in a resource file would come down to personal preference.

If they do have existing resources in their application then yes, it can be a pain to add a precompiled .res file via the IDE (and the limited resource editor/compiler that is included). In that case I suspect I'd simply use one of the resource editing tools that are available, such as Resource Tuner (which is what i used to create the precompiled .res file I attached above) or Resource Hacker (which is free but slightly more obtuse in use than Tuner); I'll grant this is slightly more complicated.

>how about set administrator right in a install tools?

sal21 is using a pretty much base VB6 install (as far as I can tell). Which means they are using the package and deployment wizard - which doesn't allow you to set access rights requirements, dating from an era where MS didn't really care about this.
 
>Manifest file is recommended

By whom? I'd wager that sal21 isn't currently using a resource file, so the complication you mention doesn't really exist. Using a separate manifest or an embedded manifest in a resource file would come down to personal preference.
It seems that manifest is your first choice. I agree with you and I wan't to give a hint of “detail" you skipped. If no need other resource file, .res is the better way.
 

Part and Inventory Search

Sponsor

Back
Top