Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在JS函数中包含变量字符串(HTA应用程序)_Javascript_Variables_Hta - Fatal编程技术网

Javascript 在JS函数中包含变量字符串(HTA应用程序)

Javascript 在JS函数中包含变量字符串(HTA应用程序),javascript,variables,hta,Javascript,Variables,Hta,我试图在cmd/c runas命令中包含变量,我使用JS函数,它给我一个错误,指定的文件找不到 我想我使用了错误的变量调用或其他东西 以下是我的功能: function runasSRVhta(){ var WShell = new ActiveXObject('WScript.Shell'); // var srvDude = document.getElementById("SRVinput").value; var SRVguy = "someadmin.sr

我试图在
cmd/c runas
命令中包含变量,我使用JS函数,它给我一个错误,指定的文件找不到

我想我使用了错误的变量调用或其他东西

以下是我的功能:

function runasSRVhta(){
var WShell = new ActiveXObject('WScript.Shell');
// var srvDude = document.getElementById("SRVinput").value;
var SRVguy = "someadmin.srv";
WShell.Run('cmd /c runas /u:sa.local\\SRVguy "c:\\windows\\system32\\mshta.exe """\\\\fs\\FIle Share\\SA Support\\ZverTools\\giveMeIPsPLZ.hta""""', 1, true);
}
它不作为someadmin.srv运行以下命令,而是运行其变量名,而不接受值

问题就在这里-
cmd/c runas/u:sa.local\\SRVguy
,SRVguy应该是var
SRVguy=“someadmin.srv”中的变量

  • 更新
我也尝试了下面的函数,它检测变量值,但我的HTA给了我另一个错误,说它找不到指定的文件

function testsrv() {
  var shell = new ActiveXObject("WScript.Shell");
  var SRVguy = "someadmin.srv";
  var SRVguyaftertext = 'c:\\windows\\system32\\mshta.exe """\\\\fs\\FIle Share\\SA Support\\ZverTools\\giveMeIPsPLZ.hta"""';
  var satavesrv = 'cmd /c runas /u:sa.local\\';
  var theend = "'" + satavesrv + SRVguy + ' "' + SRVguyaftertext + '"' + "'";
  document.write(theend);
  var path = theend;
  shell.run(theend,1,false);
}
哦,我使用document.write检查输出是否正确,以下是输出:

'cmd /c runas /u:sa.local\someadmin.srv "c:\windows\system32\mshta.exe """\\fs\FIle Share\SA Support\ZverTools\giveMeIPsPLZ.hta""""'

第二个函数似乎一切正常,但HTA会弹出一条错误消息,说明它找不到指定的文件…

尝试使用模板字符串将变量包含在字符串中,如下所示

WShell.Run(`cmd /c runas /u:sa.local\\${SRVguy} "c:\\windows\\system32\\mshta.exe """\\\\fs\\FIle Share\\SA Support\\ZverTools\\giveMeIPsPLZ.hta""""`, 1, true);
-更新

WShell.Run('cmd /c runas /u:sa.local\\' +SRVguy + ' "c:\\windows\\system32\\mshta.exe """\\\\fs\\FIle Share\\SA Support\\ZverTools\\giveMeIPsPLZ.hta"""', 1, true);

告诉我一个错误,说无效字符,我想它会认为``是一个无效字符请尝试这个WShell.Run('cmd/c runas/u:sa.local\\'+SRVguy+'“c:\\windows\\system32\\mshta.exe”“”\\\\fs\\FIle Share\\sa Support\\ZverTools\\givemeipslz.hta”“,1,true);效果很好,请将您的评论作为答案提交,我会将其标记为解决方案。