I was wondering if I am able to run a Powershell script from another program.<\/p>\n
Advertisement
Right now this is my code; (This is Turing language)<\/p>\n
Dir.Change (“C:/Users/jsargeant2/Documents/Scripts”) \nif Error.Last = eNoError then \nput “Directory changed” \nelse \nput “Did not change the directory.” \nput \"Error: \", Error.LastMsg \nend if \nput \"The current execution directory is \", Dir.Current<\/p>\n
if not Sys.Exec (“Logging_Functions.ps1”) then \nput “The Sys.Exec call failed” \nput \"Error: \", Error.LastMsg \nelse \nend if<\/p>\n
This program changes the directory to where my script is located and then runs it in the next “If” statement.<\/p>\n
I got PowerShell to pop up, but there is no text in the window and then it closes shortly after.<\/p>\n
I thought it was running but just not showing it. So to test this I had the script just create a text file in an empty folder.<\/p>\n
When I run the script it works fine, but not through my program.<\/p>\n
p.s I have changed the execution policy to every type and put it back to RemoteSigned for now.<\/p>\n
So my question is should this be working or do you have to run PowerShell scripts only from within PowerShell and will not let any other application control it?<\/p>\n
p.s I understand that almost no one will know Turing syntax but I thought it was still worth asking the question as I believe there is a “Setting” in PowerShell that I haven’t considered.<\/p>\n
Thanks in advance!<\/p>","upvoteCount":6,"answerCount":7,"datePublished":"2018-12-13T20:51:01.000Z","author":{"@type":"Person","name":"justinsargeant","url":"https://community.spiceworks.com/u/justinsargeant"},"acceptedAnswer":{"@type":"Answer","text":"
I have just figured out the solution to my problem.<\/p>\n
Powershell was not set to RemoteSigned… Well it was but not the 32bit version of Powershell which is what my program was trying to run.<\/p>\n
Opened the 32bit version as Admin and set it to RemoteSigned as well and now everything works.<\/p>\n
Holy crap that was soo easy.<\/p>","upvoteCount":0,"datePublished":"2018-12-18T17:25:54.000Z","url":"https://community.spiceworks.com/t/run-powershell-script-from-another-program-turing/688613/7","author":{"@type":"Person","name":"justinsargeant","url":"https://community.spiceworks.com/u/justinsargeant"}},"suggestedAnswer":[{"@type":"Answer","text":"
Hey All,<\/p>\n
I was wondering if I am able to run a Powershell script from another program.<\/p>\n
Right now this is my code; (This is Turing language)<\/p>\n
Dir.Change (“C:/Users/jsargeant2/Documents/Scripts”) \nif Error.Last = eNoError then \nput “Directory changed” \nelse \nput “Did not change the directory.” \nput \"Error: \", Error.LastMsg \nend if \nput \"The current execution directory is \", Dir.Current<\/p>\n
if not Sys.Exec (“Logging_Functions.ps1”) then \nput “The Sys.Exec call failed” \nput \"Error: \", Error.LastMsg \nelse \nend if<\/p>\n
This program changes the directory to where my script is located and then runs it in the next “If” statement.<\/p>\n
I got PowerShell to pop up, but there is no text in the window and then it closes shortly after.<\/p>\n
I thought it was running but just not showing it. So to test this I had the script just create a text file in an empty folder.<\/p>\n
When I run the script it works fine, but not through my program.<\/p>\n
p.s I have changed the execution policy to every type and put it back to RemoteSigned for now.<\/p>\n
So my question is should this be working or do you have to run PowerShell scripts only from within PowerShell and will not let any other application control it?<\/p>\n
p.s I understand that almost no one will know Turing syntax but I thought it was still worth asking the question as I believe there is a “Setting” in PowerShell that I haven’t considered.<\/p>\n
Thanks in advance!<\/p>","upvoteCount":6,"datePublished":"2018-12-13T20:51:01.000Z","url":"https://community.spiceworks.com/t/run-powershell-script-from-another-program-turing/688613/1","author":{"@type":"Person","name":"justinsargeant","url":"https://community.spiceworks.com/u/justinsargeant"}},{"@type":"Answer","text":"
If you post code, please use the ‘Insert Code’ button. Please and thank you!<\/p>