How to register DLL from .bat file in Windows 7 - windows

As part of a poor-mans installation (on Windows 7) I need to register a DLL from a .bat file. I provide the user with a set of files that make up the application, tell them to copy them to some (any) directory, then, as the 1st part of the install, tell them to execute my register.bat file which invokes regsvr32 on the appropriate DLL(s)
This fails with 0x80004005 (permission) error. I then try running the .bat file as an Admin. This doesn't work as it opens the command prompt in \windows\system32 which is not where the DLLs to be registered are located. As I don't know where the user has placed the register.bat file I can't put the path to the DLL files in the .bat file.
Any thoughts?

Try using %~dp0 to get the folder the batch file is stored in, like:
regsvr32 %~dp0\mylibrary.dll

You can get and use the path of the current directory like this:
set "FullPath=%cd%\Test.dll"

Related

Create a .bat file to run an exe as administrator

I've created a batch file for running a setup.exe (code below) but I'm having issues getting the setup.exe to "run as administrator". I used this guide (shortcut trick) for aid.
start "" %CD%\Setup.exe
NOTE: My files will eventually be burnt to a DVD disk. They are currently in the directory "C:\Drivers\win8.1_x64\01a.chipset".
The batch file code runs the setup.exe (without admin privileges) fine, when running the batch file by itself (i.e. not running the shortcut).
However, when I run the batch file via the shortcut, Windows gives the error "Windows cannot find 'C:\Windows\system32\Setup.exe'".
The setup.exe directory is not in the system32 folder. Why does running the batch file find the setup.exe fine but not when I run it by the shortcut (so I can run the setup.exe as an admin)?
You can either set the working directory in the shortcut itself, or run Setup.exe not from working directory (%CD%) but from directory where script is located:
start "" "%~dp0\Setup.exe"
Difference from earlier answer is there's no need to cd to %~dp0. Just run the setup with full path.
By default admin privileged scripts are starting in C:\Windows\system32\
Try to put cd /d "%~dp0" at the beginning of your script which should change the work directory to the script's one.You can check this if you want to create a shortcut with admin permissions from the command line.

Unable to open application by specifying it's location under App Paths

I have created a key(for example myapp.exe) under "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths" with below values in registry.
(Default) --> C:\Program Files\folder1\folder2\myapp.exe
Path --> C:\Program Files\folder1\folder2\;
Then I opened a command prompt and tried to open my application. But I am getting an error like "'myap.exe' is not recognized as an internal or external command,operable program or batch file."
If I add the directory where my application resides to Path environment variable, then I am able to run the application successfully from command prompt.
please let me know where I went wrong.
This is another way to start an application from the command prompt.
Create a batch file similar to the following and call it FR.BAT which is short for foxit reader in this example, and store the FR.BAT file in c:\windows or another directory on the PATH.
When you open a CMD prompt and type fr then it will launch this batch file and start the application.
#echo off
start "" "c:\Program Files\Foxit Software\Foxit Reader\Foxit Reader.exe"
Just be careful not to use a name which is the same as an existing Windows command.

Windows PATH variable

My program needs .bat file to run because the .bat file is changing some language settings, so .bat file looks like:
set lang=en
start ap.exe
It is working great but when I made installer for my app and pointed .bat file as main file, it creates a shortcut on the desktop to that .bat file. So far everything is great but when I launch that shortcut it cannot open app.exe because it can't find it on desktop.
So my question is: How can I get path to folder of .bat file so I could set proper start command? Something like:
set lang=en
S=getpath();
start S/app.exe
It is just pseudocode but I think you get point.
You can write %~dp0 to get the directory containing the batch file.
Therefore, you can write
"%~dp0app.exe"

How to run exe before or after "RunProgram" from 7zip sfx files setting on config.txt?

I am using 7zip to pack an installation (im using 7z because i need it to work in linux and windows).
From what i've been reading the config.txt file can contains this:
;!#Install#!UTF-8!
RunProgram="Installer.exe"
;!#InstallEnd#!
But what if i need to run another exe before or after running installer.exe? Is it possible like it is in NSIS?
You can specify another progrem in 'RUnProgram' config parameter. Lets say its some .bat file. At the moment program is run, files are already extracted at TEMP location. As your .bat will run then, it can call Installer.exe once script is finished preparations.

Commands Visibility at Command Prompty Not Using System32

Let's say I have a foo.exe file that I want to use it from windows command prompt. I will go to the folder which contains foo.exe and run it. Now, if I want global access for foo.exe from anywhere in the command prompt I will put foo.exe in System32 folder.
This process makes System32 a dump ground. I was wondering if there are any other ways of globally accessing the .exe or bat files without having to dump all of them in System32 folder.
Change your PATH environment variable. i.e. "set path=%path%;[newdir]"
where [newdir] is the new directory you want searched when you run commands.
The PATH Environment Variable
You can either do this programatically (StackOverFlow) or follow these instructions
How to set the path in Windows 2000 / Windows XP, another one.

Resources