Batch file on a remote computer

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
blockie
Posts: 5
Joined: 27 Aug 2014 09:26

Batch file on a remote computer

#1 Post by blockie » 27 Aug 2014 09:58

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.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Batch file on a remote computer

#2 Post by foxidrive » 27 Aug 2014 10:04

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.

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Batch file on a remote computer

#3 Post by aGerman » 27 Aug 2014 10:13

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

blockie
Posts: 5
Joined: 27 Aug 2014 09:26

Re: Batch file on a remote computer

#4 Post by blockie » 27 Aug 2014 12:05

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.

Squashman
Expert
Posts: 4470
Joined: 23 Dec 2011 13:59

Re: Batch file on a remote computer

#5 Post by Squashman » 28 Aug 2014 07:40

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.

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Batch file on a remote computer

#6 Post by aGerman » 28 Aug 2014 13:50

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

Samir
Posts: 384
Joined: 16 Jul 2013 12:00
Location: HSV
Contact:

Re: Batch file on a remote computer

#7 Post by Samir » 29 Aug 2014 05:14

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
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.

blockie
Posts: 5
Joined: 27 Aug 2014 09:26

Re: Batch file on a remote computer

#8 Post by blockie » 29 Aug 2014 07:30

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:?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Batch file on a remote computer

#9 Post by foxidrive » 29 Aug 2014 08:59

Windows 7 doesn't search the physical drive unless you change the settings. It only searches indexed files and folders.

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Batch file on a remote computer

#10 Post by aGerman » 29 Aug 2014 10:24

@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.

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

blockie
Posts: 5
Joined: 27 Aug 2014 09:26

Re: Batch file on a remote computer

#11 Post by blockie » 29 Aug 2014 11:52

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

Samir
Posts: 384
Joined: 16 Jul 2013 12:00
Location: HSV
Contact:

Re: Batch file on a remote computer

#12 Post by Samir » 30 Aug 2014 08:53

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.
You're right. :( But if it's somehow already there, then it would be like the first time. :?:

Samir
Posts: 384
Joined: 16 Jul 2013 12:00
Location: HSV
Contact:

Re: Batch file on a remote computer

#13 Post by Samir » 30 Aug 2014 08:55

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
Just out of curiosity, what does the /fs switch do? It didn't do anything on xp.

blockie
Posts: 5
Joined: 27 Aug 2014 09:26

Re: Batch file on a remote computer

#14 Post by blockie » 30 Aug 2014 14:40

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

Samir
Posts: 384
Joined: 16 Jul 2013 12:00
Location: HSV
Contact:

Re: Batch file on a remote computer

#15 Post by Samir » 01 Sep 2014 17:57

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
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.

Post Reply