Batch file on a remote computer
Moderator: DosItHelp
Batch file on a remote computer
I maintain several computers remotely. On occassion I would like to place a notebook file
on a particular user desktop and have it open on the first or second keystroke after the user gets on the computer. The first part I can do manually, that is xfer a notebook file to a folder on the remote computer. Then when the user makes the first keystroke have the notebook file popup on the desktop so it can't be missed.The text contens of the popup may be changed as needed. There also should be a way for the user to dismiss the popup.
on a particular user desktop and have it open on the first or second keystroke after the user gets on the computer. The first part I can do manually, that is xfer a notebook file to a folder on the remote computer. Then when the user makes the first keystroke have the notebook file popup on the desktop so it can't be missed.The text contens of the popup may be changed as needed. There also should be a way for the user to dismiss the popup.
Re: Batch file on a remote computer
A batch file placed in the startup group can open Notepad with a text file when the computer starts, and it would display until it was dismissed.
Re: Batch file on a remote computer
Also if you have remote access to the registry you could start a command via "RunOnce".
The local registry patch would be
"HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce"
Although I don't know how to change something remotely there ...
Regards
aGerman
The local registry patch would be
"HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce"
Although I don't know how to change something remotely there ...
Regards
aGerman
Re: Batch file on a remote computer
To keep from getting confused a little more info seems appropiate. Several of the computers in question have multiple user accounts.I would want the popup to appear when a certain user logged on.
Also what would the bat file look like? I am new to using DOS commands in this manner.
Also what would the bat file look like? I am new to using DOS commands in this manner.
Re: Batch file on a remote computer
Every user has their own startup folder in their profile. So you can just put it in that users startup folder. Been like since at least Windows 2000 or even earlier. I can't remember how NT4 worked.
Re: Batch file on a remote computer
A very simple Batch file for a short RunOnce message could be something like that.
As already mentioned I still have no idea how to remotely write to a certain user key.
Regards
aGerman
Code: Select all
@echo off &setlocal DisableDelayedExpansion
REM title of the CMD window prepended with ::@
::@important & short message
REM message, each line prepended with ::$
::$Please Note:
::$
::$Never touch a "running system"!
REM Read title
for /f "delims=" %%i in ('type %~fs0^|findstr /bc:"::@"') do set "title=%%i"
if defined title (
setlocal EnableDelayedExpansion
set "title=!title:^=^^!"
set "title=!title:&=^&!"
set "title=!title:<=^<!"
set "title=!title:>=^>!"
set "title=!title:|=^|!"
set "title=!title:"=\"!"
for /f "delims=" %%i in ("!title:*@=!") do (
endlocal
set "title=%%i"
)
)
REM compose the message
set "message="
for /f "delims=" %%i in ('type %~fs0^|findstr /bc:"::$"') do (
set "ln=%%i"
setlocal EnableDelayedExpansion
set "ln=!ln:^=^^!"
set "ln=!ln:&=^&!"
set "ln=!ln:<=^<!"
set "ln=!ln:>=^>!"
set "ln=!ln:|=^|!"
set "ln=!ln:"=\"!"
for /f "delims=" %%j in ("!message!&echo(!ln:*$=!") do (
endlocal
set "message=%%j"
)
)
setlocal EnableDelayedExpansion
REM calculate a unique identifier for the registry value name
set "strMap=0123456789ABCDEF"
set "strUID="
for /l %%i in (1 1 32) do (
set /a "x = !random! %% 16"
for %%j in (!x!) do set "strUID=!strMap:~%%j,1!!strUID!"
)
REM write to the current users registry
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce" /v "msg{!strUID!}" /t REG_SZ /d "\"!comspec!\" /q /t:70 /k \"prompt $h^&title !title!^&echo(!message!\"" /f
pause
As already mentioned I still have no idea how to remotely write to a certain user key.
Regards
aGerman
Re: Batch file on a remote computer
You could have this batch in the user's startup folder and it will execute the batch. Then the next time the system is run, it will execute the runonce. Although you'd have to figure out a way to delete the batch from the startup as well to avoid it running more than once.aGerman wrote:A very simple Batch file for a short RunOnce message could be something like that.Code: Select all
@echo off &setlocal DisableDelayedExpansion
REM title of the CMD window prepended with ::@
::@important & short message
REM message, each line prepended with ::$
::$Please Note:
::$
::$Never touch a "running system"!
REM Read title
for /f "delims=" %%i in ('type %~fs0^|findstr /bc:"::@"') do set "title=%%i"
if defined title (
setlocal EnableDelayedExpansion
set "title=!title:^=^^!"
set "title=!title:&=^&!"
set "title=!title:<=^<!"
set "title=!title:>=^>!"
set "title=!title:|=^|!"
set "title=!title:"=\"!"
for /f "delims=" %%i in ("!title:*@=!") do (
endlocal
set "title=%%i"
)
)
REM compose the message
set "message="
for /f "delims=" %%i in ('type %~fs0^|findstr /bc:"::$"') do (
set "ln=%%i"
setlocal EnableDelayedExpansion
set "ln=!ln:^=^^!"
set "ln=!ln:&=^&!"
set "ln=!ln:<=^<!"
set "ln=!ln:>=^>!"
set "ln=!ln:|=^|!"
set "ln=!ln:"=\"!"
for /f "delims=" %%j in ("!message!&echo(!ln:*$=!") do (
endlocal
set "message=%%j"
)
)
setlocal EnableDelayedExpansion
REM calculate a unique identifier for the registry value name
set "strMap=0123456789ABCDEF"
set "strUID="
for /l %%i in (1 1 32) do (
set /a "x = !random! %% 16"
for %%j in (!x!) do set "strUID=!strMap:~%%j,1!!strUID!"
)
REM write to the current users registry
reg add "HKCU\Software\Microsoft\Windows\CurrentVersion\RunOnce" /v "msg{!strUID!}" /t REG_SZ /d "\"!comspec!\" /q /t:70 /k \"prompt $h^&title !title!^&echo(!message!\"" /f
pause
As already mentioned I still have no idea how to remotely write to a certain user key.
Regards
aGerman
Re: Batch file on a remote computer
Squashman wrote:Every user has their own startup folder in their profile. So you can just put it in that users startup folder. Been like since at least Windows 2000 or even earlier. I can't remember how NT4 worked.
I did a search on one of the computers that I maintain. Searched for the word "Startup" and found only two folders. Each had one file, a HP file in one and a Norton file in the other. I was in the admin account on a W7 Professional 64 bit computer.
Does the "startup folder" have an other names? Am I able to see all the account startup folders by doing a simple search of the system drive, C:?
Re: Batch file on a remote computer
Windows 7 doesn't search the physical drive unless you change the settings. It only searches indexed files and folders.
Re: Batch file on a remote computer
@Samir
This way the message would pop up the second time the user logs on. I fear it's not what blockie is looking for and also not what I intended.
A batchfile can easily delete itself using
Regards
aGerman
This way the message would pop up the second time the user logs on. I fear it's not what blockie is looking for and also not what I intended.
Although you'd have to figure out a way to delete the batch from the startup as well
A batchfile can easily delete itself using
Code: Select all
del "%~f0"
Regards
aGerman
Re: Batch file on a remote computer
Solved! I found the startup folders for the users. I put the batch file in the users startup folder\programs\start\Warning.bat. It started a notebook file that I had put in \startup\programs.
The batch file is @echo off
Start notepad "c:\users\appdata\roaming\microsoft\windows\start menu\programs\start\xx.txt" /fs .
Simple and it works for my purposes. I jotted in my notes the code for how to delete the batch file thanks to aGerman .
Bill
The batch file is @echo off
Start notepad "c:\users\appdata\roaming\microsoft\windows\start menu\programs\start\xx.txt" /fs .
Simple and it works for my purposes. I jotted in my notes the code for how to delete the batch file thanks to aGerman .
Bill
Re: Batch file on a remote computer
You're right. But if it's somehow already there, then it would be like the first time.aGerman wrote:@Samir
This way the message would pop up the second time the user logs on. I fear it's not what blockie is looking for and also not what I intended.
Re: Batch file on a remote computer
Just out of curiosity, what does the /fs switch do? It didn't do anything on xp.blockie wrote:Solved! I found the startup folders for the users. I put the batch file in the users startup folder\programs\start\Warning.bat. It started a notebook file that I had put in \startup\programs.
The batch file is @echo off
Start notepad "c:\users\appdata\roaming\microsoft\windows\start menu\programs\start\xx.txt" /fs .
Simple and it works for my purposes. I jotted in my notes the code for how to delete the batch file thanks to aGerman .
Bill
Re: Batch file on a remote computer
Just out of curiosity, what does the /fs switch do? It didn't do anything on xp.
Heck! I don't know. I removed it and did not notice any change in performance.
I got the whole string somewhere whiole searching Google for a batch file I could use.
Now what I do iswhen it's time to put some sort of msg to a particular user is put the batch file in the appropiate folder and the notepad txt in the appropiate path. I rename the batch file something like .bat1 until I need it agian and the remove the 1 from .bat1 and compose a msg on my computer using notepad and copy it to the appropiate folder in the users profile. Then after a day or two I add the "1" back into .bat.
Bill
Re: Batch file on a remote computer
Nice! I forgot about renaming a batch file when not needed. I usually name mine to .bak (like what the old dos editor edlin would do) or .ba. I couldn't find anything on the switches too so maybe notepad just ignores them.blockie wrote:Just out of curiosity, what does the /fs switch do? It didn't do anything on xp.
Heck! I don't know. I removed it and did not notice any change in performance.
I got the whole string somewhere whiole searching Google for a batch file I could use.
Now what I do iswhen it's time to put some sort of msg to a particular user is put the batch file in the appropiate folder and the notepad txt in the appropiate path. I rename the batch file something like .bat1 until I need it agian and the remove the 1 from .bat1 and compose a msg on my computer using notepad and copy it to the appropiate folder in the users profile. Then after a day or two I add the "1" back into .bat.
Bill