Link to home
Start Free TrialLog in
Avatar of bbimis
bbimis

asked on

scripting question - move file(s) to folders then create shortcut for all and execute

How could I do this?
I would like to run maybe psexec and send 2 files to EVERYONE on my domain. I want the files to go to the c:\bbi  directory on the remote computer(s).

I know i can accomplish this with
psexec @pc1.txt -u bbi\administrator -p censored cmd.exe /c c:\bbi\exchangefix.exe

Open in new window

then repeat the psexec for the next file.

But how can i then make it based on on the operating system place a shortcut in the all users startup folder.
My thinking something like this:
@ECHO OFF
IF EXIST "c:\programdata" (
	ECHO FOUND windows 7 machine
	COPY /Y \\serverpath\exchangefix_shortcut.lnk "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup" 1>NUL 2>NUL
) ELSE (
	IF EXIST "c:\Documents and Settings" (
		ECHO FOUND XP machine
Copy /Y \\serverpath\exchangefix_shortcut.lnk "C:\Documents and Settings\All Users\Start Menu\Programs\Startup" 1>NUL 2>NUL
	) ELSE (
		ECHO CAN'T DETERMINE MACHINE
	

Open in new window


Then I need to execute the shortcut on each machine if it isn't already running.

However I can do this would be great. Thanks for the help in advance.
Avatar of Giovanni
Giovanni
Flag of United States of America image

Use "%userprofile%\Start Menu" (ran on the end-users machine) for a specific user  and "%allusersprofile%\Start Menu" variable for all users.  Both locations are a junction point which links to the correct location across varying versions of Windows.

Run SET from the command line to verify on each machine.

Of course using a logon script via GPO may be a more effective way of going about this.  :)
Avatar of bbimis
bbimis

ASKER

here is what I came up with. The experts exchange site went down so i couldn't modify my question.  Anyway here is what I have that works. But I need to figure out a way to execute the program if it isn't already running.

here is my push script:
@ECHO OFF
IF EXIST "c:\programdata" (
	ECHO FOUND Windows 7 Machine
	COPY /Y "\\bbifileserv\e\Common\ToTony\Programs I made\fix exchange annoying security popup\*.*" "C:\TONY" 1>NUL 2>NUL
	Move /Y "C:\Tony\exchangefix.lnk" "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup" 1>NUL 2>NUL
) ELSE (
	IF EXIST "c:\Documents and Settings" (
		ECHO FOUND XP Machine
		COPY /Y "\\bbifileserv\e\Common\ToTony\Programs I made\fix exchange annoying security popup\*.*" "C:\Tony" 1>NUL 2>NUL
		MOVE /Y "C:\tony\exchangefix.lnk" "C:\Documents and Settings\All Users\Start Menu\Programs\Startup" 1>NUL 2>NUL
	) ELSE (
		ECHO CAN NOT DETERMINE SYSTEM 
		)
)

Open in new window


I fire that bat with psexec.

I know I could take and do
psexec @pcs.txt -u bbi\administrator -p censored \\pathtofilel\pushexchangefix.bat

Open in new window


my question is how can i make this all in one and also how can i make sure it loaded?  like log the process name or something.  

I need it to only execute it if not already running.

Thanks!
ASKER CERTIFIED SOLUTION
Avatar of Giovanni
Giovanni
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Best thing to do is let it run from a GPO.  To ensure the GPO runs only once, check for a file (i.e. c:\checkfil.txt).  Below would be my script for the GPO:

@ECHO OFF
IF EXIST "C:\checkfile.txt" goto End
IF EXIST "c:\programdata" (
      ECHO FOUND Windows 7 Machine
      COPY /Y "\\bbifileserv\e\Common\ToTony\checkfile.txt" "C:\" 1>NUL 2>NUL
      COPY /Y "\\bbifileserv\e\Common\ToTony\Programs I made\fix exchange annoying security popup\*.*" "C:\TONY" 1>NUL 2>NUL
      Move /Y "C:\Tony\exchangefix.lnk" "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup" 1>NUL 2>NUL
) ELSE (
      IF EXIST "c:\Documents and Settings" (
            ECHO FOUND XP Machine
                       COPY /Y "\\bbifileserv\e\Common\ToTony\checkfile.txt" "C:\" 1>NUL 2>NUL
            COPY /Y "\\bbifileserv\e\Common\ToTony\Programs I made\fix exchange annoying security popup\*.*" "C:\Tony" 1>NUL 2>NUL
            MOVE /Y "C:\tony\exchangefix.lnk" "C:\Documents and Settings\All Users\Start Menu\Programs\Startup" 1>NUL 2>NUL
      ) ELSE (
            ECHO CAN NOT DETERMINE SYSTEM
            )
:End
Avatar of bbimis

ASKER

Thanks that is what I needed