Expanding %1 and other variables from a command


hi!

i need simple command open specific file (rasphone.pbk) whatever default program opening text files.

what have far:

(get-itemproperty -path 'registry::hkey_classes_root\txtfile\shell\open\command').'(default)'

which gives me output:

"c:\program files\sublime text 2\sublime_text.exe" "%1"

it executed different machines/users. may have default notepad.exe, others may have different editors.

so need replace %1 with

%appdata%\microsoft\network\connections\pbk\rasphone.pbk

while expanding %appdata%. default command is

%systemroot%\system32\notepad.exe %1

where need expand %systemroot% well.

it should 1-liner if possible because command stored in database. if need script file have find way distribute file each client well... , opening file bit much.

if it's easy in cmd better, thought powershell capable tool doing stuff in simple way. can't wrap head around it...

thanks help! :)

thanks guys different approaches - learned lot.

for specific requirements can use 1 of these:

powershell -windowstyle hidden -command "((get-itemproperty -path 'registry::hkey_classes_root\txtfile\shell\open\command').'(default)').replace('%1','%appdata%\microsoft\network\connections\pbk\rasphone.pbk') | cmd"


powershell -windowstyle hidden -command "cmd /c (cmd /c ftype txtfile).split('=')[1].replace('%1','%appdata%\microsoft\network\connections\pbk\rasphone.pbk')"


the "ftype" thing shorter.

thanks!



Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

CRL Revocation always failed

Failed to query the results of bpa xpath

0x300000d errors in Microsoft Remote Desktop client