Access "Start up" folder from CMD? - command-line

How can I get the path of the start up folder from a batch file? The only way I found was to look in the registry but I don't think thats possible with CMD.

This will set STARTUP to the location of the startup folder:
for /F "skip=4 tokens=3*" %%j in ('reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v "Common Startup"') do set STARTUP=%%k
(skip=4 is for XP, use skip=2 for Windows 7. I don't have vista to try the command there)
Also available (change the value after /v)
Common AppData
Common Programs
Common Documents
Common Desktop
Common Start Menu
CommonPictures
CommonMusic
CommonVideo
Common Templates
Common Favorites
Common Startup
Common Administrative Tools

In windows xp you can access like this
importedCountToMainTable
CD %HOMEDRIVE%%HOMEPATH%\Start Menu\Programs\Startup

Related

Simple xcopy script using variables and a target text list to copy a folder to different computers

I wrote a script that wil copy a particular folder to a list of hosts, stored in a text file.
It works great from a short source path but fails to find the folder when located in a long path, which is how i need it to function.
Thsi what i tried, which should copy the folder to the list in the text.
Code below
set source=%~dp0%data
set source2=%~dp0%\target.txt
FOR /F "TOKENS=*" %%A IN (%source2%) DO XCOPY /d /y /f /i "%source%" "\%%~A\c$\users\test\test"
pause
Error: The system cannot find the file C:\Users\lenovo\OneDrive\Company\Red.
The above path is not the full path.
I understand there may well be more modern ways to achive this such as ropcopy or powershell and am open to ideas if this is not teh best method.
Thanks in advance for any help

How to set acl permissions for specific sub-folders in many paths?

Here is an example folder path: E:\Datastore\MarcStone Bids\7401-7450\7415 Building Renovation and Addition for Van Meter Community School District - Van Meter IA\Bid Documents
Note how the second to last directory is a job #/name. I have hundreds of these paths on a windows 2008 r2 server. Inside each one exists the exact same group of 10 folders which are created by a script. They inherit their parent permissions which is fine, EXCEPT for 3 of the 10 folders require a single additional acl permission. I want to add this additional permission through a script of some kind. I've looked at vbscript, but it seems wildcards in folder paths is a complication that is better handled by powershell, but I'm really not sure.
So, I would appreciate counsel on choosing a method to perform this action and then more importantly help to build a working script.
Thoughts??
Your simple answer lays in command line tools.
Type icacls /? and for /?
Using the dir command can give you a list of folders matching.
dir *partialfoldername* /ad /s /b
Putting it into a for loop.
for /f %A in ('dir *partialfoldername* /ad /s /b) do icacls %A /grant Administrator:F

Importing Projects and Building workspace from batch file

I have this batch file
#ECHO OFF
ECHO Please Enter Path of the View, you want to update in double quotes.
SET /P variable=
SET ECLIPSE=C:\Users\gdeep\Desktop\TED-4.3.0.20110512190809.lnk
SET WORKSPACE=C:\Users\gdeep\DevCodebase_2
:LOOP
ECHO Press 'g' for Graphical Interface and 'c' for Command line.
SET /P answer=
IF /I "%answer%"=="g" GOTO GRAPHICAL
IF /I "%answer%"=="c" GOTO COMMANDLINE
ECHO Invalid Input. Please Try Again.
GOTO LOOP
:GRAPHICAL
cleartool update -graphical %variable%
GOTO CONTINUE
:COMMANDLINE
cleartool update %variable%
GOTO CONTINUE
:CONTINUE
FOR /D %%i IN (%WORSPACE%) DO RD /S /Q "%%i" DEL /Q "%WORSPACE%\*.*"
START %ECLIPSE% -data %WORSPACE%
D:
chdir "%variable%"\v4electronics
ECHO Please Ensure that Server is killed.
PAUSE
mvn clean install -Dmaven.test.skip=true -Dresource.minify.skip=true
For deleting all the projects i used
FOR /D %%i IN (%WORSPACE%) DO RD /S /Q "%%i" DEL /Q "%WORSPACE%\*.*"
Can anyone explain this to me? I copied it from somewhere and don't want to use it without understanding.
Problem with using above command is althout it seem to work, i see
The system cannot find the file specified.
The system cannot find the path specified.
as the output.
Also, the way i am deleting, will it be equivalent to if i delete them from the eclipse, by select all projects and deleting?
Another problem here is that when i have .
mvn clean install -Dmaven.test.skip=true -Dresource.minify.skip=true
in the end it works fine, otherwise, if there is any other command after it, those commands doesn't run.
After this, I then wanna import all maven projects from the Clearcase %Variable%.
And i want to do that by command line only. Can you help me with that?
Thanks for your help.
Appreciate your time.
Please correct me, If I'm wrong. I understand that you're in the MS-Windows environment.
Regarding to the question about if there is another command after the "mvn ...", they are ignored.
I use the "call" as the following: -
cd project1
call mvn clean install
cd project2
call mvn clean install
I hope this may help.
Regards,
Charlee Ch.
cleartool update -graphical %variable%
This will update a view, opening a GUI during the update (if -graphical is used) for displaying the number of files unchanged, new, modified, deleted or hijacked during this update.
See cleartool update man page.
The graphical update will let you specify how you want hijacked files and timestamps handled by said update:
Click the Advanced tab and change default options for the Update Tool.
If you need to resolve hijacked files, select a method. You have these choices:
Leave hijacked files in place
Rename the hijacked files and load the selected version from the VOB
Delete hijacked files and load the selected version from the VOB
You can also select a method for handling timestamps. You have these choices:
Set file times to current time
Set file times to version creation time
You need to enter the path of the root directory of a snapshot view: see "To update snapshot views"
FOR /D %%i IN (%WORSPACE%) DO RD /S /Q "%%i" DEL /Q "%WORSPACE%\*.*"
This will completely empty Eclipse workspace, projects and its .metadata folder, forcing Eclipse to recreate a workspace from scratch.
It seems a bit extreme, and would basically be the same as
RD /S /Q "%WORSPACE%"
(Eclipse would recreate "%WORSPACE%" when launched with -data %WORSPACE%)

Making batch file for copying

Can anyone advise me please im using Windows XP Pro on C drive and need to be able to copy a file from one drive to another. This case original will have to be renamed and old file must be put on another Partiton which is on a Server Example K drive.
Alternately There is another option using Windows 7 on a another computer instead of Windows XP Pro. So any answers appreciated.
A quick look on my old DOS book that I saved just in case that I have to make batch files says COPY is the right command.
Syntax:
COPY DRIVE:FILENAME DRIVE:FILENAME
COPY THISFILE THATFILE
If your permissions are setup to allow copying, you can use "UNC" paths to copy files across servers and drives.
Like Noah said, check out ROBOCOPY or the slightly less featured XCOPY.
Enter copy /? or xcopy /? to find out the available options - if you append >file.txt you'll get them in a text file.
XCOPY Command:
xcopy c:\sourceDirectory\*.* d:\destinationDirectory\*.* /D /E /C /R /Y
ROBOCOPY Command:
robocopy c:\sourceDirectory\*.* d:\destinationDirectory\*.* /R:5 /W:3 /Z /XX /TEE
Either of these should work for you
Have you looked into robocopy?

Tool for commandline "bookmarks" on windows?

Im searching a tool which allows me to specify some folders as "bookmarks" and than access them on the commandline (on Windows XP) via a keyword. Something like:
C:\> go home
D:\profiles\user\home\> go svn-project1
D:\projects\project1\svn\branch\src\>
I'm currently using a bunch of batch files, but editing them by hand is a daunting task. On Linux there is cdargs or shell bookmarks but I haven't found something on windows.
Thanks for the Powershell suggestion, but I'm not allowed to install it on my box at work, so it should be a "classic" cmd.exe solution.
What you are looking for is called DOSKEY
You can use the doskey command to create macros in the command interpreter. For example:
doskey mcd=mkdir "$*"$Tpushd "$*"
creates a new command "mcd" that creates a new directory and then changes to that directory (I prefer "pushd" to "cd" in this case because it lets me use "popd" later to go back to where I was before)
The $* will be replaced with the remainder of the command line after the macro, and the $T is used to delimit the two different commands that I want to evaluate. If I typed:
mcd foo/bar
at the command line, it would be equivalent to:
mkdir "foo/bar"&pushd "foo/bar"
The next step is to create a file that contains a set of macros which you can then import by using the /macrofile switch. I have a file (c:\tools\doskey.macros) which defines the commands that I regularly use. Each macro should be specified on a line with the same syntax as above.
But you don't want to have to manually import your macros every time you launch a new command interpreter, to make it happen automatically, just open up the registry key
HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\AutoRun and set the value to be doskey /macrofile "c:\tools\doskey.macro". Doing this will make sure that your macros are automatically predefined every time you start a new interpreter.
Extra thoughts:
- If you want to do other things in AutoRun (like set environment parameters), you can delimit the commands with the ampersand. Mine looks like: set root=c:\SomeDir&doskey /macrofile "c:\tools\doskey.macros"
- If you prefer that your AutoRun settings be set per-user, you can use the HKCU node instead of HKLM.
- You can also use doskey to control things like the size of the command history.
- I like to end all of my navigation macros with \$* so that I can chain things together
- Be careful to add quotes as appropriate in your macros if you want to be able to handle paths with spaces in them.
I was looking for this exact functionality, for simple cases. Couldn't find a solution, so I made one myself:
#ECHO OFF
REM Source found on https://github.com/DieterDePaepe/windows-scripts
REM Please share any improvements made!
REM Folder where all links will end up
set WARP_REPO=%USERPROFILE%\.warp
IF [%1]==[/?] GOTO :help
IF [%1]==[--help] GOTO :help
IF [%1]==[/create] GOTO :create
IF [%1]==[/remove] GOTO :remove
IF [%1]==[/list] GOTO :list
set /p WARP_DIR=<%WARP_REPO%\%1
cd %WARP_DIR%
GOTO :end
:create
IF [%2]==[] (
ECHO Missing name for bookmark
GOTO :EOF
)
if not exist %WARP_REPO%\NUL mkdir %WARP_REPO%
ECHO %cd% > %WARP_REPO%\%2
ECHO Created bookmark "%2"
GOTO :end
:list
dir %WARP_REPO% /B
GOTO :end
:remove
IF [%2]==[] (
ECHO Missing name for bookmark
GOTO :EOF
)
if not exist %WARP_REPO%\%2 (
ECHO Bookmark does not exist: %2
GOTO :EOF
)
del %WARP_REPO%\%2
GOTO :end
:help
ECHO Create or navigate to folder bookmarks.
ECHO.
ECHO warp /? Display this help
ECHO warp [bookmark] Navigate to existing bookmark
ECHO warp /remove [bookmark] Remove an existing bookmark
ECHO warp /create [bookmark] Navigate to existing bookmark
ECHO warp /list List existing bookmarks
ECHO.
:end
You can list, create and delete bookmarks. The bookmarks are stored in text files in a folder in your user directory.
Usage (copied from current version):
A folder bookmarker for use in the terminal.
c:\Temp>warp /create temp # Create a new bookmark
Created bookmark "temp"
c:\Temp>cd c:\Users\Public # Go somewhere else
c:\Users\Public>warp temp # Go to the stored bookmark
c:\Temp>
Every warp uses a pushd command, so you can trace back your steps using popd.
c:\Users\Public>warp temp
c:\Temp>popd
c:\Users\Public>
Open a folder of a bookmark in explorer using warp /window <bookmark>.
List all available options using warp /?.
With just a Batch file, try this... (save as filename "go.bat")
#echo off
set BookMarkFolder=c:\data\cline\bookmarks\
if exist %BookMarkFolder%%1.lnk start %BookMarkFolder%%1.lnk
if exist %BookMarkFolder%%1.bat start %BookMarkFolder%%1.bat
if exist %BookMarkFolder%%1.vbs start %BookMarkFolder%%1.vbs
if exist %BookMarkFolder%%1.URL start %BookMarkFolder%%1.URL
Any shortcuts, batch files, VBS Scripts or Internet shortcuts you put in your bookmark folder (in this case "c:\data\cline\bookmarks\" can then be opened / accessed by typing "go bookmarkname"
e.g. I have a bookmark called "stack.url". Typing go stack takes me straight to this page.
You may also want to investigate Launchy
With PowerShell you could add the folders as variables in your profile.ps1 file, like:
$vids="C:\Users\mabster\Videos"
Then, like Unix, you can just refer to the variables in your commands:
cd $vids
Having a list of variable assignments in the one ps1 file is probably easier than maintaining separate batch files.
Another alternative approach you may want to consider could be to have a folder that contains symlinks to each of your projects or frequently-used directories. So you can do something like
cd \go\svn-project-1
cd \go\my-douments
Symlinks can be made on a NTFS disk using the Junction tool
Without Powershell you can do it like this:
C:\>set DOOMED=c:\windows
C:\>cd %DOOMED%
C:\WINDOWS>
Crono wrote:
Are Environment variables defined via "set" not meant for the current session only? Can I persist them?
They are set for the current process, and by default inherited by any process that it creates. They are not persisted to the registry. Their scope can be limited in cmd scripts with "setlocal" (and "endlocal").
Environment variables?
set home=D:\profiles\user\home
set svn-project1=D:\projects\project1\svn\branch\src
cd %home%
On Unix I use this along with popd/pushd/cd - all the time.