How can I run multiple auto-runs from my USB? - javascript

I am attempting to make my USB somewhat like a "plug-and-go" device. I am putting scripts I need ran onto my USB, and making it so I only have to click a button or two for all the scripts to begin. I was wondering what commands I would use to do the following;
1) Whenever I plug in the USB, I would like to either hold or press a key (such as 1,2,3,4,etc) that would choose which script I ran. Is this possible?
2) Is it possible for me to plug in a USB, and with the correct scripts, not have to unplug the USB and have it run through a series of scripts (through start-ups/restarts)
A better Explanation
Is it possible that I run one script, which would require a restart, for my to keep the USB in, and as soon as the computer starts again it would run the next script specified.
Sorry if I am unclear. If you are willing to help, I am willing to explain it in a way you can understand.
Thanks!

You may be able to achieve something similar by using the Task scheduler in Windows (assuming your in a windows environment). As far as auto running scripts from flash drives its a bad idea, the majority of Antivirus software will block autorun scripts on a flash drive.

Lovely, I wanted to do this and I did. I used Command Prompt, batch language, I think, to do that.
I used this method:
record that the USB had run the first script automatically
restart the computer
login and the autorun would pop up, logically
it would run the second script because, from the record, the program knows to run another since the first had finished already
#echo off
title autorun
color 0a
mode con: cols=82 lines=25
set /p ran=<"check.txt"
if "%ran%" == "true" (goto second) else (goto first)
:first
echo Merry Easter~ (^u^)
timeout /nobreak /t 3 >nul
echo true>"check.txt"
shutdown -r -t 0
pause >nul
echo Shutdown doesn't seems to be successful, but if you want, press any key to see the next message~
pause >nul
goto second
:second
echo Happy Christmas~ [>u<]
timeout /nobreak /t 3 >nul
del "check.txt"
exit

Related

How to automatically close webpage using javascript?

I have found many questions like mine in different forums, but I couldn't find an answer that actually helps to solve my problem in any of them.
Basically, what I want is to open an URL through command prompt, it will open the browser, processes a webpage, and then I would like it to automatically close.
Why do I need this?
I have an application that runs on IIS. There are some routines I need to run everyday in my application. I can simply kick of these routines by running an URL similar to the showed below:
http://myapplication.com/DoStuff.aspx?
The Problem is that this is totally manual.
I was wondering if I could create a batch file calling my URL "start http://myapplication.com/DoStuff.aspx?", and then I could create a task on Windows to run that batch file everyday. That works for me except that the browser will not close automatically.
What I mean is, I could try it, but at the end of a week, I would have at least 5 windows opened.
What I have tried:
I have tried to solve it by using javascript, but I always end up getting this message:
scripts may close only the windows that were opened by it
It does not matter the javascript function I create using "window.close()", the windows won't close.
Chrome and Firefox returns that message.
IE let's me try to close the window, but it asks in a popUp if I really want to close it.
What you need is probably a headless browser like PhantomJS (WebKit browser without GUI). I would recommend you to use CasperJS to create scripts even more easily...
Install Phantom and Casper globally on your system and write a minimal automation script like so:
var casper = require('casper').create();
casper.start('http://myapplication.com/DoStuff.aspx');
casper.then(function() {
// Do something here...
});
casper.run();
Set a cron job (or Windows equivalent) to execute the script with the casperjs bin. Normally, it should do the trick...
Using batch files only because I strongly believe you do not need JavaScript to do this.
::start a new browser session at the given url
start iexplore "http://www.google.com"
::wait for whatever process to end if you actually have to wait
timeout 15
::kill the browser process
taskkill /im iexplore.exe /f /t
If it runs on a machine nobody interacts with, and you know the session you log into will be the last session you got out of, then you know the session you're getting into already has IE open. So you could reverse the order of the script and not care much about timing
::kill the browser already opened
taskkill /im iexplore.exe /f /t
::open a new browser session at the given url
start iexplore "http://www.google.com"
::if you have to wait, but don't know how long... leave the browser window open. We'll close it next time we run this batch file anyway.
At *nix you can create a bash script containing
#!/bin/bash
/usr/bin/chromium-browser --user-data-dir="/home/USER/.config/chromium-no-flags" "http://myapplication.com/DoStuff.aspx"
within DoStuff.aspx, use setTimeout() or other function to call window.close() when task is complete
setTimeout(close, 10000)
or
new Promise((resolve, reject) => {
// do asynchronous stuff
resolve(/* value */)
})
.then(close)
.catch(close)
For *indows equivalent of cron see
What is the Windows version of cron?
Windows equivalent to cron?
See also
Close google chrome open in app mode via command line
Open Chrome from command line and wait till it's closed
Close programs from the command line (Windows)
Killing all instances of Chrome on the command-line?

Node.js Setup Wizard ended Prematurely on Windows 7 32 bit

I am trying to install node-v0.10.35-x86.msi on my windows 32 bit system, it will automatically rolling back at the end...
I had tried some solutions given in the following link...
node.js Setup Wizard ended prematurely
none of them worked for me....
Here is my installer log file of this node.js
https://db.tt/223knP0A
Please provide quick solutions....
Try in cmd :
reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib\_V2Providers\{793c9b44-3d6b-4f57-b5d7-4ff80adcf9a2}" /s
reg query "HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Perflib\_V2Providers\{1e2e15d7-3760-470e-8699-b9db5248edd5}" /s
If one of those exist delete it.
It solve my problem.
It seems that the following command
"wevtutil.exe" im "C:\Program Files\nodejs\node_etw_provider.man"
is failing on your setup with the following error:
ERROR - Error 0x800706b5: CAQuietExec Failed
A helpful suggestion on how to fix this issue can be found at http://blogs.technet.com/b/odsupport/archive/2010/12/30/troubleshooting-office-installation-failures.aspx:
This issue can occur if the Windows Event Log service is not running.
Click on start, search and type in services.msc and hit enter.
Scroll down to the Windows Event Log service, and ensure it is set to
automatic. If it is not running right click on it and choose start.
If you get an error like the following:
Error 4201: The instance name passed was not recognized as valid by a WMI data > provider.
Then please check the permissions on
"c:\windows\system32\logfiles\wmi\RTbackup"
If the system account doesn’t have full control, grant the system account full > control and reboot.
After reboot check and see if the Windows Event Log service is started in
services.msc.
I had the same problem, solution is "Windows Eventlog". Run eventvwr.msc on the "Run" box, check "Installation" and "Application" pages of the Windows protocol section.
I tried most of them but finally I am able to fix by expanding the Node.js runtime node in order to see the Performance counters feature and disabling it.
Following video helped me:
https://youtu.be/dLsiNamyad4?t=2m30s

Use javascript to launch local file on user's machine?

I have an Excel macro that runs in a workbook that our company uses. I've made cells look like hyperlinks, so when someone double-clicks on the link it opens IBM mainframe and loads up some data. I'm writing another app for us that's web based, and I'm wondering if this same functionality is possible. I haven't seen anything on the internet that would lead me to believe I could do this, but I thought I'd ask anyway....
Public SODD As String
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
If Target.Column = 2 And (Target.Row >= 1) Then
SODD = Target.Value
Call SOLookup
End If
End Sub
Sub SOLookup()
Dim autECLPS As Object
Dim s As New AutSess
AppActivate "3270 Terminal"
s.SetConnectionByName ("A")
s.autECLPS.StartCommunication
s.autECLPS.SendKeys "[Clear]"
s.autECLOIA.WaitForInputReady (500)
s.autECLPS.SetText "SODD " & SODD
s.autECLOIA.WaitForInputReady (500)
s.autECLPS.SendKeys "[ENTER]"
s.autECLOIA.WaitForInputReady (500)
End Sub
This loads the IBM mainframe and types in the sales order number into their screen and hits Enter.
Would I be able to accomplish this same feat using something like Javascript?
Javascript may not execute files on the user's local environment. However, a server side language may do what you require. For instance, you can use AJAX(javascript) to make a call to a PHP script which can execute, say, a batch file (.bat) which can then run your macro. The PHP file could have code as simple as
system("cmd /c C:[path to your macro/.bat file]");
Again, this all depends on your configuration and environment. So to recap: Web Browser->AJAX->PHP->Macro.
Neither Javascript nor any other script that runs inside the browser is allowed to execute any file locally on a user's computer. And this is a good tihng. Imagine what would happen if any website could randomly execute programs on your computer...
Internet ressources are not trusted, therefore they are not allowed to do anything on your local computer.
If the website is running in your company's intranet, there might be a way using proprietary MS technology and the Internet Explorer with properly configured trusted sites - but I wouldn't bother with it.

How to Execute a Javascript in Internet Explorer from Command Line?

Recently at my job we have been wanting to automate our deployment process with new machines. I figured the best way to do this was by launching IE (since it's the default browser that's installed via Litetouch) via command line, which the generic code for it is as follows:
iexplore.exe http://reg.cmich.edu
Which works as expected; however the next part of the automation process is to pass IE at least a javascript file that can select the building I want to register a new NIC device at, then on the next pass I would pass it my administrative credentials.
For the most part, I can figure out by scrounging the net how to get Javascript to execute certain things in a browser like clicking links and entering text into text boxes. I'm just wondering if there's any way during running my batch script that I can pass IE a .js file to execute after the browser opens.
Any help would be greatly appreciated!
You can bypass IE completely by using cscript.exe to run JavaScript.
> cscript.exe "path/to/file.js"
cscript.exe is in c:\windows\system32.
Keep in mind that globals like window and document will not be available because you have no head.
Here you go enable by command
1) Go to Start -> Run
2) Type : CMD (then enter)
3) You will get command prompt window on screen.
4) Type below command and ten enter :
regsvr32 jscript.dll
5) Now check Internet Explorer. You will have javascript enabled.
Hope this would help you to solve your problem.

How to handle signout when the browser in close in flex 3?

My project had audit module, which includes each and every action of the user to be recorded.
When the user closes the browser the audit regarding the logout has to be stored in the database.
I found one solution on the net, but it is working in my machine's IE but failed to work in the friends machine's IE why?
The code is:
window.onbeforeunload = clean_up;
function clean_up()
{
var flex = document.${application} || window.${application};
flex.myFlexFunction();
}
I placed this code in the index.template.html file in the html-template folder under flex src.
I also placed the below code in my main application.mxml file:
ExternalInterface.addCallback("myFlexFunction",btnLogout);
and I defined the logout function.
Ok, here is the deal. CAN NOT BE DONE RELIABLY. If this is for audit... you are out of luck and deliver a half baked approach to start with.
Why?
Go to your task manager, kill the IIS process - nothing logs out. No audit. Ergo - the solution does most likely not fulfill the legal audit requirements ;)
Another approach:
Call a service exvery X seconds from the running page. Like every 5 seconds.
Assume client dies when you dont receive call for 2 * X seconds (like after 10 seconds).
This way you realize when the client does not connect anymore. Does not stop the user from pulling the network cable and conrinuing viewing, so a failure of the audit method call should wipe the HTML content ;)
But at least you handle browser crashes / terminations, too.

Categories

Resources