NppExec Execute Batch containing Powershell worked on XP, doesn't on 7
-
Our IT department is in the process of update our PCs from XP to Windows 7 (I know, we’re a bit late, and we’re upgrading to still be out of date). One of the things we do very often is edit batch files within Notepad++ and then execute them with a keyboard shortcut using NppExec. The exact script that we were using on XP (shown below) still runs on Windows 7, but ended up running without Delayed Expansion being turned on (it is already turned on for every individual computer at the system level). We have thousands of batch files, so we didn’t really want to have to go through each one and add setlocal enabledelayedexpansion to each one.
The text in my npes_saved.txt is as follows:
::Run Batch
NPP_CONSOLE ?
NPP_SAVE
NPP_RUN “$(FULL_CURRENT_PATH)”We’re using NppExec 0.5.3 (again, a bit behind, but given that we were still on XP that shouldn’t be too surprising).
After posting over on SourceForge I was able to figure out what we needed to change the last line to this:
NPP_RUN cmd /V:ON /C “$(FULL_CURRENT_PATH)”
This fixed the batch file issue (though I still don’t understand why it was an issue in the first place), but now my powershell commands are running into a similar issue (note that the powershell commands are being called from within the batch with the powershell -f “test.ps1” command).
Previously we had IT go around to each computer in our department and execute the setexecutionpolicy remotesigned command as an admin to allow powershell to run for everyone, but now when I try to run a powershell script from within a batch from Notepad++ I get the following error:
File “test.ps1” cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at http:\go.microsoft.com/fwlink/?LinkID=135170
I do not get this error if I just double click the batch from Explorer.
Any suggestions on how to get powershell working (without having to go through and change the commands to be powershell -ExecutionPolicy Unrestricted -File “test.ps1” in all of my batch files) would be greatly appreciated.
-
I don’t have any clue about powershell and its security and to be honest, I do not really
understand what you are trying to achieve.If it is all about changing the batch files manually, then you might think of using the
find replace dialog with a regular expression and find in files option.If it is about executing the batch files on the newly creates windows 7 computers then how
are they organized? Within a domain/active directory? I strongly assume that you can assign
a policy to allow powershell script execution. Or what about using sysinternals psexec tool?
Do you use tools like microsoft operation manager or microsoft system manager center.
Tools like tivoli, netiq, nagios … (It’s been a while since I was in charge of doing stuff like this
so it might be that the names changed over time but I guess you get the point what I’m trying to ask)Cheers
Claudia -
I honestly have no idea what most of what you said means, since I’m not in IT and haven’t had to be the one to set up any of this stuff, but I can pass it off to the guy that’s setting up our computers and see if he has any idea. :-)
I don’t have any clue about powershell and its security and to be honest, I do not really understand what you are trying to achieve.
If it is all about changing the batch files manually, then you might think of using the find replace dialog with a regular expression and find in files option.All I’m trying to achieve is having the PowerShell scripts run correctly when they’re called from a batch that we’re running on Windows 7. It worked fine on XP, and it works fine if we double click the batch instead of running it from Notepad++, so I’m trying to figure out how to get it to work from Notepad++ without having to edit each script. We had considered the regular expression/find in files option (and that may end up being the best solution), but if there was an easier way (like there was to fix the batch issue) I was hoping to find it.
I strongly assume that you can assign a policy to allow powershell script execution.
I know that we did have setexecutionpolicy remotesigned run on each computer to get our PowerShell scripts working, if that’s what you mean. If not, could you elaborate a bit more?
-
as said, I have no idea about powershell security but the error you get
states that executing the powershell script is disabled so I have to assume that the setting
setexecutionpolicy remotesigned isn’t enough in this case.The open point which is confusing me is, that you want to run the batch script via notepad++ and nppexec.
OK - but from every converted (XP to Win7) PC? Or from your local PC to access the converted PCs remotely?
Because, if you want to run it on every converted PC, why not double click the batch instead of
opening notepad++, load the batch file and then run via nppexec?It might be that my thoughts are useless for you, so in that case just ignore it - I just thought
to give a hint about rethinking if it is really needed or if it can be solved in a different way.Cheers
Claudia -
The PCs aren’t really converted. My local PC is XP, but the new VM I’m on is Windows 7, and I just copied over as many settings as possible. Most people do just double click the batches, which works fine, but there are two people (myself included) that tend to create the batches, and it’s more convenient to be able to do the testing with a shortcut from within Notepad++ rather than having to go back to the folder and double click the batch between each change. If the batch doesn’t need to be edited before running then we always are just double clicking the batch, but some also have variables that we need to set before running.
I did end up finding the solution on another site though! I ended up needing to run Set-ExecutionPolicy RemoteSigned from both C:\Windows\system32\cmd.exe and C:\Windows\SysWOW64\cmd.exe and then everything work correctly. I appreciate the replies to try to help me figure this out.