question

CarlJeffreys-2491 avatar image
0 Votes"
CarlJeffreys-2491 asked YoungYang-MSFT answered

run a remote EXE with argument, from a user share but have the command run on the server that the share resides on, not local machine.

I have an executable that requires an argument to follow it, namely a root directory.

I have the executable installed with i's dependancies on a server.

A user will add content to the root directory, and then need to execute the exe. However, to supply the argument to the executable I need to call it in a command line.

How do I go about creating a link for users who access a remote share, so that a user may click on an object, and launch the application on the share along with it's argument, and have it so that all teh work takes place on teh remote server, non on the local machien of the user trying to launch the app.

I;ve tried a few things in powershell and CMD, but can't get the app to function remotely, with the additional required string dictating the root area...

Any help very welcomed

windows-server-powershell
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

RichMatheisen-8856 avatar image
0 Votes"
RichMatheisen-8856 answered CarlJeffreys-2491 commented

What are the things you've tried???? Was Invoke-Command one of them? The PowerShell script will run on the local machine, but the application will run on the remote server. They'll still have to wait for the command to complete, but it won't be running on the local machine.

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

tried Invoke-Command it fails to identify the path added to the executbale.

0 Votes 0 ·

and to be clear, the Invoke-command powershell does call the exe, but I need to .exe to launch wiht a folder path as a variable appended. If I were to run it on the machine where it;s installed via cmd line I would switch the the correct directory location, and type in the following:

<CORRECT DIRECTORY>:DatafileLoader.exe "d:\rootfilepath"

This works while on the server as me, I need to to be able to launch by certain users from a shared drive so that they can run it on demand.

hope that gives context. I hae gone into more details in the comments on youngyang-msft post below.

Any help would be hugely appreciated. :)

0 Votes 0 ·
YoungYang-MSFT avatar image
0 Votes"
YoungYang-MSFT answered CarlJeffreys-2491 commented

If you want to get help on the script, please show the command or script you are trying so that members and experts of our forum can help you. (Remember to delete the personal privacy section)

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Forgive me, My head is pickled. I have tried this as my last effort:


$User = <USERNAME>
$PWord = ConvertTo-SecureString -String <INSERT PASSWORD> -AsPlainText -Force
$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $User, $PWord

$s = New-PSSession -ComputerName "SERVERNAME" -Credential $credential

Invoke-Command -Session $s -Command {"D:\incomingdatafiles\datafileloader\datafileloader\callDatafileUploader1.ps1"}

The "callDataFileUploader1.ps1" script then executes the actual .exe with path appended

For clarity the application I need to run lives in a file structure liek this: D:\incomingdatafiles\datafileloader\datafileloader\ though it is shared to the users as somethign different:
\\SERVERNAME\DataFile Upload Share\DataFileLoader\DataFileLoader\

the executable is called, say, datafileloader.exe but needs to be run with a specified root directory after it.....


0 Votes 0 ·

In this case the command can be run in CMD (after changing the directory to the location of the exe) as DatafileLoader.exe "d:\incomingdatafiles". all of this lives on the server/share on the server.

User can connect to share and see any powershell or cmd batch files and run them. But the jobs don't work.

Tried CMD batch to change directory and run it no joy.
Attempted using task scheduler to call a script on demand no joy.

It appears to either try to run the job locally on teh user machine (in which case it can't find the path for D:) or if it does ru in the context of the server (which I did get working) it fails to see the d:\incomingdatafiles path that is appended to the exe....

Any ideas at all woudl be highly appreciated!?

0 Votes 0 ·
RichMatheisen-8856 avatar image
1 Vote"
RichMatheisen-8856 answered RichMatheisen-8856 commented

How about this?

 $Directory = "d:\rootfilepath"
    
 # this is not really the preferred way
 Invoke-Command -Computer SERVERNAME -ScriptBlock {& "D:\incomingdatafiles\datafileloader\datafileloader\callDatafileUploader1.ps1 $using:Directory"}
    
 # This is safer (and preferred)
 Invoke-Command -Computer SERVERNAME -ScriptBlock {Start-Process -NoNewWindow -FilePath "D:\incomingdatafiles\datafileloader\datafileloader\callDatafileUploader1.ps1" -ArgumentList $using:Directory}



· 8
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I'm trying this today.

It looks like a good option, though I now need to be sure the exe is called in the calldatafileuploader1.ps1 correctly. Is it possible to call the ecexutable directly with the argumentlist tags?

as in use:

Invoke-Command -Computer SERVERNAME -ScriptBlock {Start-Process -NoNewWindow -FilePath "D:\incomingdatafiles\datafileloader\datafileloader\callDatafileUploader1.ps1" -ArgumentList $using:Directory}

but replace the calldatafileuploader1.ps1 with datafileloader.exe ?
Hoping this will work, and I feel I'm close thanks to your help.

Thanks

0 Votes 0 ·

What are you questioning when you say that you you need to be sure that the executable is called correctly?

You can, if you'd like, use PsExec or WIMIC to run a command on another machine, but parameter passing (if there are double-quotes involved) can sometimes present a problem because of how the Windows shell handles quoting. Or you could even use New-PSSession, but that is probably a step too far.

There's no way (that I know of) of running an executable installed on a remote machine ON the machine where the executable is installed without establishing some sort of remote session (either persistent or temporary).

0 Votes 0 ·

Yeah, that's sort of my issue.

I tried a new-pssession and couldn;t get it working.

The .exe just lives on the server, and interacts with nothign but the files on the server. I just need a way for a user to trigger it. For me to run it, I log on to the server, open a cmd prompt, cd to teh directory and then just type the exe in with it's needed parameter, in this case > datafileloader.exe "d:\incomingdatafiles".

As this is done on the server it executes no issue.

I try to batch it, powershell it, shortcut etc 1 of 2 things happens.

Either the exe is not called at all, or on the occasions where I can get it to launch, it cant see the file path d:\incomingdatafiles.

Cheers

carl

0 Votes 0 ·
Show more comments
DSPatrick avatar image
0 Votes"
DSPatrick answered CarlJeffreys-2491 commented

You can use PSExec for this.
https://docs.microsoft.com/en-us/sysinternals/downloads/psexec




--please don't forget to Accept as answer if the reply is helpful--




· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Tried it, still fails to execute....

0 Votes 0 ·
YoungYang-MSFT avatar image
0 Votes"
YoungYang-MSFT answered

Hi, given that this post has been quiet for a while, this is a quick question and answer. Has your question been solved? If so, please mark it as an answer so that users with the same question can find and get help.
( Does the latest problem idea from RichMatheisen-8856 help you? )

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.