My Java app runs a command like this :
String Command="C:\A_Test\Dir_PC_Customizer\Chinese_English_Dictionary_PinItem.cmd";
Runtime.getRuntime().exec(Command);
I packaged it into a Jar file and it runs fine from C:/ drive. But after I copied it into a USB key-chain drive, it won't run.
And my Chinese_English_Dictionary_PinItem.cmd file is :
@echo off
set ITEM=
set TASKBAR=
set ITEM=/item:"C:\A_Test\Dir_Chinese_English_Dictionary\Chinese_English_Dictionary.exe"
set TASKBAR=/taskbar
echo on
:: Pin to Taskbar
cscript //nologo PinItem.wsf %ITEM% %TASKBAR%
When it's run from C:/, the output looks like this :
Command = C:\A_Test\Dir_PC_Customizer\Chinese_English_Dictionary_PinItem.cmd
Result :
Executing : C:\A_Test\Dir_PC_Customizer\Chinese_English_Dictionary_PinItem.cmd
C:\Dir_PC_Customizer>cscript //nologo PinItem.wsf /item:"C:\A_Test\Dir_Chinese_English_Dictionary\Chinese_English_Dictionary.exe" /taskbar
Property item is now = C:\A_Test\Dir_Chinese_English_Dictionary\Chinese_English_Dictionary.exe
Property taskbar is now =
Microsoft Deployment Toolkit version: 6.1.2373.0
------------ Initialization PinItem -------------
The /item switch specified with value: C:\A_Test\Dir_Chinese_English_Dictionary\Chinese_English_Dictionary.exe
The /taskbar switch was specified.
Function-GetSpecialFolder: Cannot determine special folder for CSIDL_PROFILES
Item "C:\A_Test\Dir_Chinese_English_Dictionary\Chinese_English_Dictionary.exe" pinned successfully
------------ Departing PinItem -------------
PinItem processing completed successfully.
But when it's run from USB drive, the output looks like this :
Executing : C:\A_Test\Dir_PC_Customizer\Chinese_English_Dictionary_PinItem.cmd
F:\Dir_PC_Customizer\dist>cscript //nologo PinItem.wsf /item:"C:\A_Test\Dir_Chinese_English_Dictionary\Chinese_English_Dictionary.exe" /taskbar
Input Error: Can not find script file "F:\Dir_PC_Customizer\dist\PinItem.wsf".
Note : they are executing the same file :
C:\\A_Test\\Dir_PC_Customizer\\Chinese_English_Dictionary_PinItem.cmd
they are just executing from C:/ or from F:/
What's obvious is : when run from C:/ , it's : C:\\Dir_PC_Customizer>cscript
When run from F:/ , it's F:\\Dir_PC_Customizer\\dist>cscript
And the error message says : "F:\\Dir_PC_Customizer\\dist\\PinItem.wsf" not found, because PinItem.wsf and other few files are in : F:\\Dir_PC_Customizer [ and in C:\\A_Test\\Dir_PC_Customizer ] , not in dist.
My question is : if I want to make it be able to run from any drive : C:/, F:/ or G:/, what should I do ?
I guess one way to do it is to tell it "although I'm running in "F:\\Dir_PC_Customizer\\dist", but pretend I'm running from "C:\\A_Test\\Dir_PC_Customizer", but how to tell it to switch directory ? That's the key.
我找到了答案,当应用程序运行时,将多余的文件从父目录复制到当前目录,以便找到它们。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.