My batch should solve a issue, but it doesn't quite work. I think it's simple, i just don't see it. I know it needs Admin, but i shortend the code to where the problem actually is.
copy "Data\invisble.vbs" "%appdata%\Roaming\Microsoft\Windows\Start Menu\Programs\Startup"
cd "%appdata%\Roaming\Microsoft\Windows\Start Menu\Programs\Startup"
start invisble.vbs
cls
Without seeing the rest of the code it's hard to know the context.
Please note that the %appdata% environment variable changes for each user.
Also note that copy "Data\invisble.vbs" specifies a relative path.
The easiest way to pinpoint the issue is to open up a command prompt and run each line and verify the results.
Related
I want to start with a little disclaimer:
I read this thread on a similar issue to mine, but it seems like the solution doesn't work. It might just be me not understanding it completely but here I am asking for clarification.
My goal is to copy a shortcut to the start menu programs folder conserving all of its attributes, icon and start in value. I thought making a copy would be simple but it seems like my brain can't understand anything today.
So here's the actual xcopy argument:
#echo off
xcopy "%~dp0\file.lnk" "%userprofile%\Start Menu\Programs\file.lnk\" /p /v /f
pause
I have tried every combination of adding/removing the file name, with/without the \ at the end and any combination of both... I also tried running the batch file as administrator just in case.
The #echo off is just a habit and the pause is to allow me to read any error messages that could pop up. I also put the extra arguments into the xcopy line to try to get more information. It doesn't seem to help me a lot though.
I'm starting to think the issue is completely isolated from the other thread.
As suggested by SomethingDark, changing the path from %userprofile%\Start Menu\Programs\ to %AppData%\Microsoft\Windows\Start Menu\Programs\ fixed my issue.
I'm trying to write a small bat script to put on my teams desktops and allow them to update their personal macro file with mine when ever I push out an update or have created new tools.
I have the following
xcopy "O:\abc Supply chain\Supply Chain Team\David Peters\Excel\Macro File" "%AppData%\Roaming\Microsoft\Excel\XLSTART\" /y
under CMD is says 1 files copied yet there isn't anything in the XLSTART folder.
can you pleased tell me what I'm doing wrong
many thanks
Not sure about your configuration, but for me the Roaming folder is already included in the value of the %AppData% variable.
"%AppData%\Roaming\Microsoft\Excel\XLSTART\"
^......^
So, probably you should use "%AppData%\Microsoft\Excel\XLSTART\"
I'm trying to output my logfiles to a subfolder relative to my install script, and MSIExec doesn't seem to like it when used with the "/l*v" command. I've tried variations of %~dp0Logs (with and without quotes, etc.). If I manually enter the full path like: /l*v c:\scripts\logs\%computername%.txt" it works fine, but the script is always going to be in different locations (USB, network, etc.).
I see references online to using the %temp% system variable which I guess works, but not the parent lookup folder variable of %dp0. And I'm using the same variable elsewhere in my script for other things, like running the MSI and file copy commands (copy "%~dp0Files\Images\%LogonBackgroundWinXP%"...). I've even tried setting a variable like: Set LogFolder=%dp0\logs, but that doesn't seem to work either.
Am I missing something or am I just going to have to find another folder lookup method just for my log files?
Thanks,
Brian
I guess all I needed was a few hours away from this and lunch! Works perfectly fine, not sure what I was doing wrong before. I was going to do a copy command afterwards, but now I don't have to.
Hi I want to stop a batch file if it is being run from a particular drive. I have tried somehting like this, it doesn't work though. I would appreciate it if someone has a better idea.
if %CD%=="^.*C:\" (goto :CDrive)
Where :CDrive is an error message saying that the user is trying to run it from the wrong drive.
Cheers
Chris
You can use a substring to check:
if "%CD:~0,2%"=="C:" goto CDrive
Another option might be that you just explicitly set the drive you're expecting:
pushd X:
or use full paths instead of relative ones.
I am currently writing a .bat batch file that executes an installation file. Before it runs the installation file I check to see if the directory exists to avoid re-installing the application.
I do this by using a If Not Exist filename statement. If the installed file doesn't exist, I then execute the installation file.
For some reason, when I test it with the application where it has been installed already, it is still trying to reinstall the application over it.
Here is a snippet of my code:
cd "C:\Documents and Settings\John\Start Menu\Programs\"
pause
If NOT exist "Software Folder"\ (
start \\filer\repo\lab\"software"\"myapp"\setup.exe
pause
)
Where SoftwareFolder is a subdirectory of "C:\Documents and Settings\John\Start Menu\Programs\". I am checking to see if it exists in my Programs folder.
I know nothing is wrong with my start command. I have a feeling something is wrong with my beginning CD command or one of its parameters.
Thanks a lot, guys!
Use the FULL path to the folder in your If Not Exist code. Then you won't even have to CD anymore:
If Not Exist "C:\Documents and Settings\John\Start Menu\Programs\SoftWareFolder\"
I noticed some issues with this that might be useful for someone just starting, or a somewhat inexperienced user, to know. First...
CD /D "C:\Documents and Settings\%username%\Start Menu\Programs\"
two things one is that a /D after the CD may prove to be useful in making sure the directory is changed but it's not really necessary, second, if you are going to pass this from user to user you have to add, instead of your name, the code %username%, this makes the code usable on any computer, as long as they have your setup.exe file in the same location as you do on your computer. of course making sure of that is more difficult.
also...
start \\filer\repo\lab\"software"\"myapp"\setup.exe
the start code here, can be set up like that, but the correct syntax is
start "\\filter\repo\lab\software\myapp\" setup.exe
This will run: setup.exe, located in: \filter\repo\lab...etc.\
As in the answer of Escobar Ceaser, I suggest to use quotes arround the whole path. It's the common way to wrap the whole path in "", not only separate directory names within the path.
I had a similar issue that it didn't work for me. But it was no option to use "" within the path for separate directory names because the path contained environment variables, which theirself cover more than one directory hierarchies. The conclusion was that I missed the space between the closing " and the (
The correct version, with the space before the bracket, would be
If NOT exist "C:\Documents and Settings\John\Start Menu\Programs\Software Folder" (
start "\\filer\repo\lab\software\myapp\setup.exe"
pause
)