Restore Batchfile, VB script shortcut in new System XP - windows-xp

In my old system (XP) I created many shortcuts in a folder on my desktop to open programs like eclipse, notepad++, etc. and some script files. I assigned shortcuts like
Cnrl+Alt+E for Eclipse, Cnrl+Alt+N for notepad, etc.
I have backed up and restored the shortcuts folder on the desktop and batch/script file folder to my new system in the same path.
Is there any script to register all the shortcut to registry in one go?

The hotkey is a function of the file.
XP looks in 4 places to discover hotkeys:
%UserProfile%\desktop
%AllUsersProfile%\desktop
%UserProfile%\Start Menu
%AllUsersProfile%\Start Menu
and in these three file types:
*.lnk
*.pif
*.url
as long as the files are in those locations, the hotkeys should still work
This vbs script will show you the hotkey assigned to a file:
on error resume next
set WshShell = WScript.CreateObject("WScript.Shell" )
Set Arg=Wscript.Arguments
set lnk = WshShell.CreateShortcut(Arg)
If lnk.hotkey <> "" then
msgbox Arg & vbcrlf & lnk.hotkey
End If
use it with the filename passed to the script, e.g. thescript.vbs %UserProfile%\desktop\myshortcut.lnk

Related

Windows Powershell Basic Questions - new user

When trying to open a file with text editor VIM, I am unable to open the file unless VIM (shortcut) is in my current working directory. As an example, I am able to write start firefox to open a firefox window. However, start vim C:\filepath\filename.txt does not work unless a vim shortcut is in my current directory. How do I get around this?
Also, is there a way to have a program execute a file in the current working directory without having to reference the entire file path? For example instead of Start-Process vim C:\Users\User\Desktop\File\file.txt is there an available path shortcut like Start-Process vim ~\file.txt with ~ representing the current working directory?
The OS need to determine the full path of the exe, no matter what.
There's 2 ways that it will happen.
You're calling the executable from it's working directory
The executable location is in the Windows environment variable.
You can view the PATH variable content through this simple statement
$env:Path -split ';' | sort
You sill see that the Firefox path is listed there, but not the one from VIM.
That's why the former can be started by it's executable name and the latter require the full path.
You need to add VIM directory to your PATH variable if you want to be able to call it just by typing vim
Otherwise, if you have restricted access or don't want to edit that variable, you can also set a $vim variable, then invoke it whenever you want to call the executable.
Regarding the second part of your question
Powershell use the dot as a reference to the current directory .\file.txt.
You can also just specify the filename without anything else file.txt.
Both backslash \ & slash / work for filepath so .\file.txt and ./file.txt are both valid ways to reference the file.
Use ..\ to reference the parent directory (e.g. ..\file.txt)
$Vim = "c:\Path\To\Vim.exe"
& $vim "file.txt"
& $vim ".\file.txt"
#Forward slash also work for paths
& $vim "./file.txt"

Powershell vs GUI shortcuts

I have a file named new.txt. Using GUI I can create a shortcut, for example, "new.lnk". When I click on "new.lnk" file, Notepad is opened with the contents of "new.txt" file. When I create the shortcut using PowerShell
NEW-ITEM -TYPE SYMBOLICLINK -TARGET "NEW.TXT" "NEW.LNK"
I can see the contents of the file using
CAT "NEW.LNK"
but the shortcut file is not working in the GUI: it does nothing.
I expect to see the contents in Notepad editor. The properties of the file created using GUI and PowerShell are the same, except for "Start in" information: blank when the short cut is created using PowerShell and with the path file directory when using GUI.
Symbolic link (symlink) is not the same as Windows shortcut. A symbolic link is created on file system level - it says "here's a file with such filename, but the content is actually in this other file". It's size is 0 Bytes, as it just points to other file.
It would be more proper to name the file "new-linked.txt" instead of "new.lnk".
A shortcut ".lnk" is a separate file that is interpreted by Windows shell. It contains a path to the target file (among other additional properties). If you create shortcut from UI and then try cat my.lnk, you'll see the content of the shortcut file itself, not the target file.
For creating a Windows shortcut from Powershell, see How to create a shortcut using PowerShell.

AHK code to locate the residing folder and highlight the active file

It’s often requires to quick locate the folder location of open active file and highlight or select the active file while working on different software applications. Quick locating the residing folder needed for finding related files in same folder, rename of the opened files or residing folder or move the file to different related folder. Current options require navigating through the loads of folders to find and locate the specific folder where it’s buried with bunch of similar other files (similar to find needle in a haystack). Microsoft Office suite has built-in feature named “document location” which can be added to quick access toolbar. But it only allow to see the folder location or full path but no single click command or key available (AFAIK) to conveniently jump to that locating folder and highlight/identified the opened file so that further operation (e.g. rename, move) could be done on that specific file/folder. This is also the case for other software applications where native program have options to get full path but no way to jump to the specific file/folder. Considering one of Microsoft Office suites application (e.g. word) as test cases the processes I could imagine as follows;
1 Get the full path (D:\Folder\Subfolder\Mywordfile.docx) of currently opened word document
2 Close the file
3 Explorer command to select and highlight the file in folder given full path (process 1)
Operation on file/folder as desire manually and double click to return to file operating applications (e.g. word).
In my assessment for Implementation of above tasks following are possibilities
Task 1 Microsoft Word has a built-in function called "document location" to get the full path of the opened document and its currently possible to copy the file path in the clipboard.
Task 2 Close the file (Ctrl+W or Ctrl+F4)
Task 3 AHK code for Explorer command to select the file for a given full path (available in Task 1)
I am facing difficulties in Task 3 and I tried each of these but so far no luck
Clipboard := “fullpath” ; Full path (D:\Folder\Subfolder\Mywordfile.docx ) copied from Word
Run explorer /e, “Clipboard”
Run %COMSPEC% /c explorer.exe /select`, "%clipboard%"
So far above explorer command only take me to my documents folder not in the specific folder location (path in Task 1). I am curious know what would be the right explorer code to select the file for a given full path in clipboard. Appreciate for supporting AHK code or better way to do this task. Thank in advance.
I'm not clear on why your sample code doesn't work. I suspect it's because of the extra characters.
After running this command Windows Explorer will be open and have the desired file selected (if it exists).
FullPathFilename := "e:\temp\test.csv"
Explorer := "explorer /select," . FullPathFilename
Run, %Explorer%
I don't know if you tried the other approach, but I think this is simpler and shorter:
1) Store the full path of the document in a string: oldfile = ActiveDocument.FullName
2) SaveAs the document with ActiveDocument.SaveAs
3) Delete the old file with Kill oldfile
All this is from VBA directly, no need to use Explorer shell. The same exists for the other applications.
Here is a fully working code for the Word Documents:
Sub RenameActiveDoc()
Dim oldfile As String
Set myDoc = ActiveDocument
'1) store current file
oldfile = myDoc.FullName
'2) save as the active document (prompt user for file name)
myDoc.SaveAs FileName:=InputBox("Enter new name", "Rename current document", myDoc.Name)
'3) Delete the old file with
On Error GoTo FileLocked
Kill oldfile
On Error GoTo 0
Exit Sub
FileLocked:
MsgBox "Could not delete " & oldfile, vbInformation + vbOKOnly, "File is locked"
End Sub
With contribution of Ro Yo Mi I am able to come up with following solution. However I am assuming that there might better solution to this task.
;;; Customize Document Location (Choose form All Commands) in Quick Access Toolbar and get its position (#4 for my case)
#If WinActive("ahk_class OpusApp") || WinActive("ahk_class XLMAIN") || WinActive("PPTFrameClass")
#p:: ;Close Word/Excel/PowerPoint Document and Locate in Explorer Folder Location
clipboard = ;empty the clipboard
Send !4 ; Select full path while document location at #4 position in Quick Access toolbar
Send ^c ; copy the full path
ClipWait ; waits for the clipboard to have content
Send {esc}
Send, ^{f4} ; Close opened document only but keep Word/Excel/PPT program running
Explorer := "explorer /select," . clipboard
Run, %Explorer%\
return

Open text file and program shortcut in a Windows batch file

I have two files in the same folder that I'd like to run. One is a .txt file, and the other is the program shortcut to an .exe. I'd like to make a batch file in the same location to open the text file and the shortcut then close the batch file (but the text file and program remain open).
I tried this with no luck:
open "myfile.txt"
open "myshortcut.lnk"
Also didn't work:
start "myfile.txt"
start "myshortcut.lnk"
I was able to figure out the solution:
start notepad "myfile.txt"
"myshortcut.lnk"
exit
This would have worked too. The first quoted pair are interpreted as a window title name in the start command.
start "" "myfile.txt"
start "" "myshortcut.lnk"
Don't put quotes around the name of the file that you are trying to open; start "myfile.txt" opens a new command prompt with the title myfile.txt, while start myfile.txt opens myfile.txt in Notepad. There's no easy solution in the case where you want to start a console application with a space in its file name, but for other applications, start "" "my file.txt" works.
The command-line syntax for opening a text file is:
type filename.txt
File types supported by this command include (but are not limited to): .doc, .txt, .html, .log
If the contents is too long, you can add "|more" after "type filename.txt", and it will pause after each screen; to end the command before the end of the file, you can hold Ctrl + C.
I use
#echo off
Start notepad "filename.txt"
exit
to open the file.
Another example is
#echo off
start chrome "filename.html"
pause
You can also do:
start notepad "C:\Users\kemp\INSTALL\Text1.txt"
The C:\Users\kemp\Install\ is your PATH. The Text1.txt is the FILE.
"location of notepad file" > notepad Filename
C:\Users\Desktop\Anaconda> notepad myfile
works for me! :)
In some cases, when opening a LNK file it is expecting the end of the application run.
In such cases it is better to use the following syntax (so you do not have to wait the end of the application):
START /B /I "MyTitleApp" "myshortcut.lnk"
To open a TXT file can be in the way already indicated (because notepad.exxe not interrupt the execution of the start command)
START notepad "myfile.txt"
The command start [filename] opened the file in my default text editor.
This command also worked for opening a non-.txt file.
If you are trying to open an application such as Chrome or Microsoft Word use this:
#echo off
start "__App_Name__" "__App_Path__.exe"
And repeat this for all of the applications you want to open.
P.S.: This will open the applications you select at once so don't insert too many.
Try using:
#ECHO off
ECHO Hello World!
START /MAX D:\SA\pro\hello.txt
Its very simple,
1)Just go on directory where the file us stored
2)then enter command i.e. type filename.file_extention
e.g type MyFile.tx
To open a file with default software just need to type the path of the file or, if you are at the file location, the file name.
C:\Users\MyName>C:\User\MyName\Desktop\hello.txt
or
C:\Users\MyName\Desktop>hello.txt
If you want specific program like notepad you can specify it first.
C:\Users\MyName>notepad C:\User\MyName\Desktop\hello.txt
or
C:\Users\MyName\Desktop>notepad hello.txt
Note that notepad is usually default text editor for .txt, in this case would make more sense to type notebook only to open a .cs/.cpp/.py file if your default for that files is any IDE and you just want to see the file on notebook
Regarding the batch file it will work the same way but to open them at the same time and let the command line go away you should use:
start "title" {filename}
So the command can open the file and return to next line immediately.
start "" C:\Users\MyName\MyFolder\foo.exe
start "" C:\Users\MyName\MyFolder\notes.txt
or
start "" foo.exe
start "" notes.txt
The last one only works if the batch file is on the same location of the files.
If you plan on using the console to open the batch file and you want the console to close at the end you should indeed write exit on last line.
When in doubt, it always helps to read the docs:
>help start
Starts a separate window to run a specified program or command.
START ["title"] [/D path] [/I] [/MIN] [/MAX] [/SEPARATE | /SHARED]
[/LOW | /NORMAL | /HIGH | /REALTIME | /ABOVENORMAL | /BELOWNORMAL]
[/NODE <NUMA node>] [/AFFINITY <hex affinity mask>] [/WAIT] [/B]
[command/program] [parameters]
"title" Title to display in window title bar.
path Starting directory.
B Start application without creating a new window. The
application has ^C handling ignored. Unless the application
enables ^C processing, ^Break is the only way to interrupt
the application.
I The new environment will be the original environment passed
to the cmd.exe and not the current environment.
MIN Start window minimized.
MAX Start window maximized.
SEPARATE Start 16-bit Windows program in separate memory space.
SHARED Start 16-bit Windows program in shared memory space.
LOW Start application in the IDLE priority class.
NORMAL Start application in the NORMAL priority class.
HIGH Start application in the HIGH priority class.
REALTIME Start application in the REALTIME priority class.
ABOVENORMAL Start application in the ABOVENORMAL priority class.
BELOWNORMAL Start application in the BELOWNORMAL priority class.
NODE Specifies the preferred Non-Uniform Memory Architecture (NUMA)
node as a decimal integer.
AFFINITY Specifies the processor affinity mask as a hexadecimal number.
Picture for the visual learners:

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.