I have a simple bat file that runs an access macro when executed, i need to know how to execute this bat file from a asp page, i have given all the permissions to the iusr_machinename for that particular folder containing the script file and the asp file.
Thank you
Note: I don't want to run anything on the client system, i just want to run a bat file on the same system the asp application is running
Assuming you understand the security implications of doing this, the code is as simple as:
set wshell = CreateObject("WScript.Shell")
wshell.run "c:\path\to\file.bat"
set wshell = nothing
I just ran this on a virtual instance without giving any special permissions to IUSR_* and it ran an xcopy without error or interference.
Another issue you will face is when your BAT file throws a prompt or wants to open some kind of dialog. It's really difficult to handle output, so make sure your BAT file runs without error before looking at further issues with the script.
Whether this code works in your environment is a matter of your security settings.
I finally make this to run changing IIS Application Pool defaults ( identity property ) from "ApplicationPoolIdentity" to "LocalSystem"
Related
I'm currently working on automating a powershell script to make a dump of a small DB.
The database is accessible through a company Sharepoint and I am leveraging an IQY file exported from said Sharepoint to read the database contents.
When I run the script manually (i.e. calling it from the command line), it works with no issues, but when I try and start the script from Task Scheduler, the following exception is raised:
System.Reflection.TargetInvocationException
the line that is generating the exception is:
$iqy = $xl.Workbooks.Open($query, 2, $true)
Where $xl is a new Excel.Application ComObject, created correctly and $query is a string containing the full file path of the iqy file.
As for my configuration, I'm trying to run my script on a Windows Server 2008R2, using a local administrator user (same user that is supposed to launch the scheduled script), which is also authorized to access the Sharepoint. I'm running Powershell 3.0. I'm not loading any Sharepoint-related snapins.
The only answers I found poking around hinted at granting "Trust" to the IQY file location and the Sharepoint itself in Excel. That did not help.
The Exception also seems to point at a sharepoint issue, but since the script runs fine when started manually, I cannot understand how it could be anything to do with Sharepoint.
Am I missing some intricacy of the Task Scheduler?
Any help would be greatly appreciated.
Never mind, I seem to have found an answer.
If anyone is encountering the same issue, it appear the Excel Com Object has a bug that does not allow it to run from the Task Scheduler if you set it to run regardless of whether the user is logged in.
To circumvent that create the following 2 folders on the machine where the script is supposed to run:
(32Bit, always)
C:\Windows\System32\config\systemprofile\Dektop
(64Bit)
C:\Windows\SysWOW64\config\systemprofile\Desktop
After creating the folders, it worked as expected.
Source: http://social.technet.microsoft.com/Forums/windowsserver/en-US/aede572b-4c1f-4729-bc9d-899fed5fad02/run-powershell-script-as-scheduled-task-that-uses-excel-com-object?forum=winserverpowershell
I have a QT application. When I use my created application launcher to start it, it doesn't work.
However, if I go to terminal and run the application from there, it works.
I'm wondering what their differences are.
Thanks.
Maybe your application launcher doesn't contain the right command and environment?
How is your launcher trying to start the program? Are any errors being reported?
It could be that the current directory is not set as expected. Or the command line parameters being sent aren't formatted correctly. Hard to say without seeing some code or an error message.
I have been looking at an issue for a week straight and have been unable to figure it out and I am desperate for the fix.
On a client site, we have two environments: UAT and PROD. UAT works perfect (Please keep this in mind). We are now trying to deploy the solution to PROD but certain parts of the solution are not working.
We have developed an asp.net application that we provide to clients to allow them to invoke SSIS packages (there are a couple of drop downs that they first select then click a button named "invoke").
When the user clicks the Invoke button, a batch file named InvokeSSIS.bat is called that assembles a command line call to dtexec with the appropriate parameters.
I'm having a problem with a particular package that is responsible for calling an executable which generates a spreadsheet that i will be importing into my system.
The executable is on an mapped H:\ drive.
I have modified the InvokeSSIS.bat batch file to capture the command the batch file is generating. If I execute this command from the command line, it works perfectly. From the webapp Invoker, it executes the package but the tasks responsible for calling the executable doesn't execute as the entire package takes only 1 second to complete (whereas it should take about a minute.)
The executable DOES have a GUI, but it is NOT interactive. This is because when you call the GUI with specific parameters, it automatically runs in batch mode and executes a macro used to generate the desired spreadsheet.
I know this is ok because it works on the UAT server AND it works from the command line!
I have checked the permissions on the executable (bu right-clicking the executable and clicking properties.) I have granted Full Control on the executable to the same user specified as the identity tab of the application pool i am using.
Can someone please help me? As I said I am dying over here!
Please let me know if you have any ideas or what other info you need.
Environment (both UAT and PROD)
OS: Windows Server 2003
IIS 6
asp.net 2.0
SQL Server 2008
Thanks!
Steve
You can't use a mapped drive with IIS.
You must use the \\servername syntax to reach files on other systems.
I agree with user544284 that this is at least in part a mapping issue. I'll ignore for a minute the complete insanity of having a web application call a batch file to start an executable that's on a remote network drive through a drive letter mapping.
Most likely the UAT box has something set up that maps that drive letter for you which Prod is missing.
The only other possibility is a security violation is occurring. Running .exe's from a network drive is generally frowned on. Do the two environments have the exact same version of windows? Are they configured the same with regards to UAC? Any differences here are going to be important.
Which brings up an interesting thought. I wonder if someone logged in to the UAT server using the same account credentials the app pool is using and added the ip address of the machine where the exe lives to the list of "Local Intranet" sites... Or, if they installed SSIS on the UAT server itself.
Just because YOU can log in to the server and run it on the command line means nothing. You have to find out if the drive letter is mapped at all for the user that the web app is running under and whether that user has the required security bits and whether the local OS will allow it regardless.
Okay, I can't ignore it: hairbrained is the nicest adjective I can come up with for this "architecture". Do yourself a favor and go back to the drawing board on this one. It has the word "brittle" written all over it, as you have already found. Instead of building out a batch file to call dtexec, just do it directly either by something like this or this.
I have a vbs file that runs fine and I want to run it under an IIS7 application name. Can this be done? If so, how?
thanks
You could look under "Handler Mappings" in IIS and add one similar to ASP which is how I used to run VBScript on the server side years ago. This does imply that the file is on a web server and you are OK with HTML output of the result.
Just for fun, I was wondering how to do this. I found an article on the Microsoft support site which told me this was possible at one time. As of IIS 7.5 this is even easier than the article suggests. You simply need to create the mapping in IIS:
Steps
Go to the IIS configuration and select the site you'd like to use
VBS files with.
Go to the Handler Mappings configuration for that site.
Click Add Script Map... on the right hand side.
Set the Request Path to *.vbs
Set the Executable to "C:\Windows\System32\cscript.exe" //NOLOGO %s %s
Set the Name to something you'll remember if you need to.
Restart IIS (possibly optional but I did this)
Then, test it with a script such as the following:
WScript.Echo "Content-Type: text/html"
WScript.Echo
WScript.Echo "If you see this, it worked."
Save it as test.vbs in your site and go to the URL to see the results. Every script used this way must begin output with the first two lines of this script or IIS will not use it.
Note: I also have the CGI (from the Windows installation disk) and Fast-CGI (from the Windows download center) modules installed. I'm not sure whether either of these are actually needed though.
I've installed IIS7 on my workstation and enabled IIS6 compatibility so I can test classic asp pages (for some old projects here at work).
Some pages work, but others don't.
I receive:
Serverobject error 'ASP 0177 : 800401f3'
Server.CreateObject failed
/master.central.be/master_connection.asp, line 55
800401f3
On that line i've got:
Set dicTalenLabels = Server.CreateObject("Scripting.Dictionary")
Anybody got some ideas what todo to fix this?
Edit:
As suggested by Michael Pryor, i've ran a vbscript with similar code and it was succesful. So it probably has something todo with permissions. Currently trying to figure out which files exactly...
Do I need to add IUSR to scrrun.dll? When trying, I do not have permission, although i'm a adminstrator.
Edited: He's running 32 bit vista, so it's definitely not a 64 bit issues.
Make a test.vbs file and put this in it
Dim o: Set o = CreateObject("Scripting.Dictionary")
Then run it like so
cscript.exe test.vbs
Does it give you the same error?
If it does, then the regsvr32 is failing or something is wrong with the registry keys it would normally put in the registry.
If it doesn't fail, it's likely that the user you have running your asp page (by default it is IUSR_machinename) doesn't have permissions on either ther registry keys it needs, or the actual .dll
0x800401f3 means that the "Scripting.Dictionary" is incorrect or not found. The Scripting.FileSystemObject is provided by the same dll file, and I know that some hosts have disabled this by unregistering the dll file, which would also disable the Dictionary object. Could you check if the Scripting.FileSystemObject works?
Both objects are provided by Windows\System32\scrrun.dll (or Windows\SysWOW64\scrrun.dll if you're executing 32bit on 64bit host). Check the permissions on this file, and verify what privileges your asp script executes as.
Take a look at:
Tips for Classic ASP developers on IIS7
More Tips and Troubleshooting Help for Classic ASP Developers
Both the links are from Bill Staples' blog, he's one of the head honchos on the IIS side of things and the tips in the first link sorted me out when I was trying to get Classic ASP up and running.
I've found that calls to system objects such as
set rs = server.createobject("adodb.recordset")
and
set fs = server.createobject("scripting.filesystemobject");
sometimes fail after running fine for weeks on a production server. It's not a great solution, but manually recycling the app pool fixes it. Also, setting the app pool to recycle every few hours is a way to keep it fresh. Just make sure that you don't accidentally log everyone off (if using session for credentials).
It could be that the developer forgot to 'close' and 'set to nothing' the objects. Any objects you create using 'set' need to be allowed to dispose by setting them to nothing after use.
set rs = server.createobject("adodb.recordset")
rs.open sql, db, 1, 3 ' adOpenKeyset, adLockOptimistic
' some process here
rs.close
set rs = nothing