Solved

how can i invoke schtasks.exe command from a web application

Posted on 2006-11-07
10
776 Views
Last Modified: 2012-06-21
My code is:

String FileName =Server.MapPath("batdir")+"\\firstcommand.bat";
            FileContent = "schtasks.exe /create /tn \"task1\" /tr \""+FileName+"\" /sc daily " ;
            FileInfo taskfile = new FileInfo(FileName);
            if (taskfile.Exists) taskfile.Delete();
            FileStream fs = new FileStream(FileName, FileMode.CreateNew, FileAccess.Write);
            StreamWriter sw = new StreamWriter(fs);
            sw.Write(FileContent);
            sw.Close();
            fs.Close();
            System.Diagnostics.Process.Start(FileName);

but when this code runs, nothing happen. Does anybody help me?
0
Comment
Question by:andreni78
  • 4
  • 2
  • 2
10 Comments
 
LVL 6

Expert Comment

by:sodalitas
ID: 17891143
Step through your code in debug mode.

After line 1 check that the value of FileName is what you expect.
After line 2 check that the value of FileContent is what you expect.
After line 3 check that the value of taskfile is the file object.
After line 4 check that the file is deleted.

<you should be cleaning up taskfile here>

After line 5 check that an empty file has been created.
After line 7 check the contents of your file.

wrap the entire block of code in a Try..Catch ex as Exception..Finally block and put a breakpoint in the Catch section and if you are getting in there, check the value of ex.
0
 
LVL 11

Expert Comment

by:ethoths
ID: 17891290
Try this...

Dim myProcess As System.Diagnostics.Process = new System.Diagnostics.Process()
myProcess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal
myProcess.Start

It might be starting th eprocess but in a hidden manner. You could also use the task manager to see if the process is being created but you'd need to know the process name.
0
 

Author Comment

by:andreni78
ID: 17898725
thanks sodalitas, ethoths
I run the above code in a web application, not a window app. I still get nothing with your suggest.
0
 
LVL 6

Expert Comment

by:sodalitas
ID: 17898838
Can you post the results of the debugging steps?
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 11

Expert Comment

by:ethoths
ID: 17898865
An ASP.Net app hey, are you expecting this to run on the client or the server?

I'm assuming the server.

I'm not sure what schtasks.exe  is but it looks liek a console app to me so you need to open a console window if you want to see any output.
0
 
LVL 11

Expert Comment

by:ethoths
ID: 17898913
Hang on - I thought it might have something to do with scheduled tasks. You need admin rights to run this app. A web app runs under MACHINENAME\ASPNET (or NETWORK_SERVICE in 2003).

You need to impersonate or use the some programmatic credentials.

0
 

Author Comment

by:andreni78
ID: 17899198
hi ethoths
I don't know how to have admin rights with programmatic credentials. Can you give me a code snippet. Thanks in advandce
0
 
LVL 11

Accepted Solution

by:
ethoths earned 500 total points
ID: 17899645
Give this a go.

        Dim p As New System.Diagnostics.Process
        p.StartInfo.UserName = "Administrator"
        Dim pas As New System.Security.SecureString
        Dim c As Char
        For Each c In "Password"
            pas.AppendChar(c)
        Next
        p.Start(FileName)
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now