Message Description Popup while sending message to same network in CMD - windows

I want to send message from Dell-PC to Acer-PC
Both are connected to same wifi network.
Dell-PC - Windows 10
Acer-PC - Windows 7
But when ever i use msg command, i get the following:-
The command i use:-
msg /SERVER:Acer-PC * /TIME:20 "Welcome!"

This answer is an hybrid of Batch and VBScript
You will need to enable LocalAccountTokenFilterPolicy value in remote computer:
In that computer open CMD as administrator and type:
reg add HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System /v LocalAccountTokenFilterPolicy /t REG_DWORD /d 1 /f
It should return The operation completed successfully.
Next, create the message box file. For that use a tool called PsExec from Windows Sysinternals
When you have downloaded PsExec, run the following command:
PsExec \\Acer-PC -e CMD /c echo CreateObject("WScript.Shell").Popup "Welcome!",20,"" ^> C:\MessageBox.vbs
To run the message box, type the following from your computer (Acer-PC):
PsExec \\Acer-PC -e WScript.exe C:\MessageBox.vbs
It will appair the message during 20 seconds

Related

How to delete the contents of temp folder in remote machine through command

I have a requirement where i need to delete the contents of the temp folder on number of remote windows machines.
i tried below wmic command to delete
WMIC /node:...** /user:xxxx /password:xxxx path cim_datafile WHERE "path='%Winddir%\temp*.tmp' AND Extension ='tmp'" delete**
But it throws an error saying
ERROR:
Description = The RPC server is unavailable.
Please suggest me a way to delete temp folder contents on remote machine.
Most simple way - if you're not strictly forced to use WMI, you can do that with psexec:
PsExec.exe \\<computer> cmd /c "rmdir /s /q %windir%\temp\"
or, if you're not logged into domain admin or global workstations admin account -
PsExec.exe -u <user> -p <password> \\<computer> cmd /c "rmdir /s /q %windir%\temp\"
If should not completely delete the folder since Windows keeps some files open and locked inside it, but anything not read-only or locked would be deleted, both files and folders.
Then, to do this with a list of computers, just use a cmd file like this (list.txt contains just computer names/ips, without \:
for /F %%s in (list.txt) do (
echo %%s
start "" /min PsExec.exe \\%%s cmd /c "rmdir /s /q %windir%\temp\"
)
Start command makes all psexec processes run in parallel and minimized so you don't have to wait for each computer to finish before starting another
psexec.exe is a part of sysinternals package from M. Russinovich, I'd like to leave a direct link but don't know if it's permitted or not.
I think it should be able to connect to remote pcs if you have access to file shares and remote computer management (and admin rights of course)

Remote folder on remote pc batch script

I currently install printers by going to a network location in an explorer window and typing in the location and it auto installs ex: \server\printer
I am trying to make a simple batch script that prompts user for a computername, then when they enter it, it should open up that location on that remote pc.
#echo off
set /p deviceid="Enter Device ID: "
EXPLORER \\%deviceid%\c$
echo Installing Printer...
EXPLORER \\server\printer
Currently this will bring up the C drive of the remote PC and install the printer on MY pc instead of the remote pc. I was using that just for testing purposes, but you can see what i'm trying to do.
You can get PSEXEC from https://technet.microsoft.com/en-us/sysinternals/pxexec.aspx. To use it you would want to do something like
set /p deviceid="Enter Device ID: "
psexec \\%deviceid% -u "username" -p "password" -i -d "\\server\printer"
And depending on what you're doing exactly, that will execute w.e on the device you are trying to get this installed on. Alternatively you could make a script that will make a seperate script then execute that script after having it copied to the computer and that will install the printer.
#echo off
Echo Device ID
set /p deviceid=
Echo Server Name
set /p server=
Echo Printer
set /p printer=
set "out=\\%deviceid%\c$"
> "%out%\Printer.bat" RunDll32.EXE printui.dll,PrintUIEntry /in /n "\\%server%\%printer%"
psexec \\%deviceid% -u "username" -p "password" -i -d "C:\Printer.bat"
timeout /t 5
I do believe either would work. I am not as seasoned as most people on here but I do believe this will work. And if your server and printer name does not change you can just set them here and not have to have them set within the script.

Running the .bat batch file in administrator mode

Iam trying to synch certain computers to a TimeServer within the network, hence i've written a simple batch script to do the task. I've put into our WDS server.
How do i run it in administrator mode.
If i open the cmd prompt as administrator it starts with "C:\Windows\System32\"
this is where i want to run so how do i achieve it.I dont want to schedule it nor i want to use RMB Click and select "Run as Administrator"
OS: Win 2012R2
My batch file contains.
reg add HKLM\SYSTEM\CurrentControlSet\services\w32time\Config /v MaxNegPhaseCorrection /t REG_DWORD /d 0xffffffff /f
reg add HKLM\SYSTEM\CurrentControlSet\services\w32time\Config /v MaxPosPhaseCorrection /t REG_DWORD /d 0xffffffff /f
w32tm /config /syncfromflags:manual /manualpeerlist:"132.186.XX.XX 132.186.127.XX 132.186.192.XX 132.186.XXX.XX" /largephaseoffset:120000
net stop w32time
net start w32time
w32tm /resync
Thanks in Advance
Create a shortcut to the batch file.
Right click on the shortcut, go to properties -> shortcut tab -> advanced.
Tick run as adminstrator
Add this to the start of your batch file:
runas.exe /savecred /user:#administratoraccount# "%windir%/System32/cmd.exe"
Replace #administratoraccount# with the username of an admin.
The first time you run it, it will ask for the password of that admin account. Enter it. Unless the password is removed from the windows credential locker or the password or username of that admin is changed or the username is disabled, whenever the batch file is run from then on, it will automatically run cmd.exe as administrator.

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?

Run BAT as admin (w/o shortcut)

So, I am trying to create a .bat to taskkill a specific program in Win7.
I am using the command:
taskkill /f /im "LCore.exe"
The .bat needs to be run as admin in order to work it seems so I have created a shortcut to it to run automatically in admin mode as specified in another thread (How to code a BAT file to always run as admin mode?).
However, when using the Microsoft Mouse and Keyboard Center to map one of my additional keys to run the shortcut it automatically runs the target of the shortcut rather than the shortcut itself which doesn't have the admin privileges needed (when selecting to map the shortcut it automatically changes the path to the target, manually setting the path returns a 'not found' error).
So basically I was wondering if there is another way that doesn't involve creating a shortcut to automatically run a .bat with elevated privileges.
#ECHO OFF
OPENFILES>NUL 2>&1
IF "%ERRORLEVEL%"=="0" GOTO :YouAreAdmin
GOTO :GetAdmin
:GetAdmin
ECHO.Set UAC = CreateObject^("Shell.Application"^) > "StartAsAdmin.vbs"
ECHO.UAC.ShellExecute "%~fs0", "", "", "runas", 1 >> "StartAsAdmin.vbs"
StartAsAdmin.vbs
DEL "StartAsAdmin.vbs"
EXIT /B
:OK
REM Your code starts here!
ECHO.
ECHO. If you see this, you have started as admin this bat file.
PAUSE>NUL
EXIT
Sorry, but I am new! :)
So first, OPENFILES command checks if you have runned program as administrator, like any command that needs administrator privileges. If you type >NUL 2>&1 after a command, CMD will hide any message from that command and will redirect error. So if you have troubles running a simple command action like OPENFILES, the only error that you can have is that batch file doesen't have administrator privileges. And if %ErrorLevel% is 0 (you have no errors running that command), it seems that you started application as administrator, so it steps to :OK label. But if %ErrorLevel% is not 0 (there is a problem), it seems that application doesen't have administrator privileges. So it will start automatly as administrator from a temporary VBScript generated by that batch file, then is started, and then deleted.
In Windows 7 you don't need to write additional scripts, because it has built-in "PowerShell" instrument. Try the following :
powershell.exe start-process taskkill.exe -verb runas -argumentlist '/f /im "LCore.exe"'

Resources