Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2006-11-07
10
Medium Priority
?
789 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 6

Expert Comment

by:sodalitas
ID: 17898838
Can you post the results of the debugging steps?
0
 
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 2000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

610 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