Relative path on WshShell

158 views Asked by At

I'm trying to use the following script on various machines, so i need to put in a relative path, if the file is in the same diretory works fine, but if i create a folder in this diretory the code dont recognize the location

<!DOCTYPE html>
<html>

<head>
    <hta:application applicationname="WRLK" 
    id="WRLK" 
    version="1.0" 
    innerborder="no" 
    caption="no" 
    sysmenu="no" 
    maximizebutton="no" 
    minimizebutton="no" 
    icon="loader2.ico" 
    scroll="no" 
    scrollflat="yes" 
    singleinstance="yes" 
    showintaskbar="no"
    contextmenu="no" 
    selection="no"
    />
    <script type="text/javascript" language="javascript">
        function Window_onLoad(){
            window.resizeTo(window.screen.availWidth/6.5, window.screen.availHeight/2.143);
            window.moveTo(screen.availWidth - (window.screen.availWidth / 6.90) , screen.availHeight - (window.screen.availHeight /1));
        }
        function CLOSE() {
            WshShell = new ActiveXObject("WScript.Shell");
            WshShell.Run("WIs-1.hta", 1, false);
            
        }
        function Trian() {
            WshShell = new ActiveXObject("WScript.Shell");
            WshShell.Run("/WIsWRLK/Triangulacao/trian.hta", 1, false);
        }
        function nodongle() {
            WshShell = new ActiveXObject("WScript.Shell");
            WshShell.Run("file:///C:/Users/hebert_costa/Downloads/HTA%20WIs/WIsWRLK/nodongle/nodongle.hta", 1, false);
        }

this work:

function CLOSE() {
            WshShell = new ActiveXObject("WScript.Shell");
            WshShell.Run("WIs-1.hta", 1, false);
        }

but this don't work:

 function Trian() {
            WshShell = new ActiveXObject("WScript.Shell");
            WshShell.Run("WIsWRLK/Triangulacao/trian.hta", 1, false);
        }


any help?

1

There are 1 answers

0
LesFerch On

As per the comment, set the CurrentDirectory to the script's directory, which can be obtained from document.URL. Use backslashes in Run commands. See example below.

You can create your objects once at the top of the script. You don't have to repeat that code in every function.

Be sure to explicitly set your document mode. The code in the question will, by default, run in IE=7 mode. Since an hta:application section was included, the highest possible mode, using a single file solution, is IE=9. You can get the benefit of IE=11 mode, while retaining hta:application settings, by splitting your HTA into two files.

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="x-ua-compatible" content="IE=9">
<hta:application
icon=loader2.ico 
singleinstance=yes 
contextmenu=no 
scroll=no 
selection=no
showintaskbar=no
>
<script language="JScript">
oWSH = new ActiveXObject("WScript.Shell");
oFSO = new ActiveXObject("Scripting.FileSystemObject");

MyPath = document.URL.substr(7);
MyFolder = oFSO.GetParentFolderName(MyPath);
oWSH.CurrentDirectory = MyFolder;

x = screen.availWidth / 2;
y = screen.availHeight / 2;
window.resizeTo(x, y);
window.moveTo((screen.availWidth - x)/2, (screen.availHeight - y)/2);

oWSH.Run(".\WIsWRLK\Triangulacao\trian.hta", 1, false);

</script>
</head>
<body>
</body>
</html>