NirCMD run multiple commands from a context menu - command-line

I would like to run a few NirCmds when running an application such that it will change the primary display to the extended monitor, run the app and then switch back when finished. Ideally I would like to create this as a context menu option. Since this is using multiple commands I thought of using the script functionality from nircmd such as:
script "$folder.desktop/testscript.ncl"
with the script containing the lines I needed:
setprimarydisplay(2)
exec max "???.exe"
waitprocess ???.exe setprimarydisplay(1)
However I am not sure how to pass the process name from the context menu into the script or if this is even possible. Does anyone know how to do this or am I approaching this the wrong way?
I have the process location from the context menu as %1, so the issue is really just passing this into the script. Something like:
script "$folder.desktop/testscript.ncl" -%1

Related

Powershell IE automation how to pass flags to navigate method?

How can I pass flags to the InternetExplorer navigate method
Specifically, no cache or read or write to history
https://learn.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/platform-apis/aa768360%28v%3dvs.85%29
What Ive tried so far, but just basing this off the BrowserNavConstants enum. Im not sure how one would pass more than one flag, nor if this is even taking effect, as my script seems to be pulling a page from previous execution.
https://learn.microsoft.com/en-us/previous-versions/dd565688(v%3Dvs.85)
$brFlgs = 4
$ie.navigate("my-url-here",$brFlgs )

How to trigger RegenerateUserEnvironment forcibly

I'm currently having trouble applying logon script(powershell) on windows servers.
The logon script has the line to set user environment variables but the variables don't look like being applying immediately from the result of set command on command prompts.
I've been looking at the behavior through process monitor while logging on to the new session.
And finally I have found the newly created variables need to be associated with RegenerateUserEnvironment function on shell32.dll.
I'm able to look at the correct result of set command after RegenerateUserEnvironment is called.
So I was wondering whether we had a way to trigger RegenerateUserEnvironment function and it needs to be executed on powershell.
Can you shed some light on this?
Best Regards,
Haewon

How to Load PowerShell Functions On-Demand?

In my personal PowerShell profile that loads whenever I start PowerShell, I want to include a set of functions by calling a function.
So I want to do something like this:
function loadMyFunctions{
. \MyFunctions.ps1
}
Now, in MyFunctions.ps1 I have a function:
function bobtest{
write-host "My name is Bob Newhart."
}
I am able to load the script MyFunctions.ps1, but after that is loaded I am not able to call bobtest in the console - I get the error message The term bobtest is not recognized...
However, if I just load the script outside the function then that script is loaded and I can call bobtest normally - but that means that I can't just not load MyFunctions when the profile is loaded - I have to load MyFunctions and cannot choose.
You see, I want to load the other functions on demand and not have them available until I choose.
Is there another way to do this or can it even be done?
Have a look at this page, How to Create PowerShell Modules and Manifests.
This will enable you to create a module which will have all your custom functions! Then inside of your loadMyFunctions cmdlet add Import-Module NewModuleName.
This will enable you to use your cmdlets.
Hope this Helps,
Lachlan
Best way is to use modules. But still if you want to get in some different ways , then you can try with your approach.
See the below screenshots which I have performed.
I have a function addition which simply does addition and I saved it as funct1.ps1
Now I am calling the same function from another function of the other script just using dot source without using as module and it results me properly.
Funct1.ps1
Triggered the function from another function in another script .
Hope it helps...!!!

How to store and call a simple mongodb procedure

I often call the same commands in MongoDb command shell, for example :
db.user().find().pretty();
How would you store and call back this command ?
Ideally converting it to something like this :
db.findp( 'user' );
I believe this is NOT what your looking for, now that I read your question again: http://docs.mongodb.org/manual/applications/server-side-javascript/
Instead you are looking to modify the console in such a manner to make your life easier.
I should note, right now, that there is actually an extension which can do this sort of auto-formatting for you made by 10gen: https://github.com/TylerBrock/mongo-hacker
However if you wish to modify the files behind MongoDBs console a little more then you will need to do some manual labour.
There is a rc script in your home directory called .mongorc.js. In this file you can place any custom code you like (as #Asya mentioned) and it will actually become a command within the console.
In you rc file you could place a function like:
DB.prototype.pfind = function(col){
return this[col].find().pretty();
};
Or you could write:
DBCollection.prototype.pfind = function(){
return this.find().pretty();
};
Then you should be able to do:
db.pfind('users');
Or with the second command:
db.users.pfind();
Of course this method is for Linux, I am unsure about Windows, however, Windows should have an rc type script somewhere I believe.

Cron Job in Kohana

How do you create a cron job in Kohana? I setup a regular controller which extends off the Controller_Base and I ran the command line:
/usr/bin/wget http://domain/controller/custom_cron
But I can't get it to work. It just doesn't execute. No error, nothing. I didn't put any special code in my controller ... just what I need to run my program. So if there is like a special command to call a cron job, I didn't add it (cause I don't know what it would be).
Also, I need it to make MySQL calls so I would need to include the db info and connection and what not (if it doesn't do that automatically). And I work off a custom model. How would I include that (if it doesn't do it automatically).
Thank you.
php /path/to/index.php --uri=controller/action/etc/etc
Calling it like this pretty much makes it act exactly like in a web environment. The only difference is the protocol for requests is 'cli'. You'll need to keep that in mind if you are generating links.
So if there is like a special command
to call a cron job, I didn't add it
(cause I don't know what it would be)
Daft question - have you added that wget command to crontab or similar?
If on the other hand you're looking to make a "poor man's cron", you could try creating a hook that runs on every page load and checks the last time the job was run, perhaps storing the last timestamp in a file or database.
I had to use cURL as my fire-this-script command in curl
Ex:
30 18 * * * curl "http://domain.com/controller/method"
php and wget didn't work, even when calling index.php and adding the uri as suggested above.
Also, FYI, Most transparent way to test this was just running the line from SSH manually to see what the results were. Once I confirmed it was working there, then I put it in the cron.