HighTechTalks DotNet Forums  

running external Dos commands or programs

Dotnet VJSharp microsoft.public.dotnet.vjsharp


Discuss running external Dos commands or programs in the Dotnet VJSharp forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Dubh
 
Posts: n/a

Default running external Dos commands or programs - 04-18-2005 , 05:39 PM






I have come up with a problem which I can't seem to be able to resolve. I
want to be able to map a drive but haven't been able to get the
java.lang.runtime to do this for me. To check where the problem might lie, I
called the notepad program instead. Now when I check the Processes under Task
Manager I find that there is a NOTEPAD.EXE process running but there is no
window for the process nor a corresponding application. Can anyone help me as
I am completely baffled. I'm using what I think is standard java code:

Process p = Runtime.getRuntime().exec(command);

Brian

Reply With Quote
  #2  
Old   
Dubh
 
Posts: n/a

Default Re: running external Dos commands or programs - 04-19-2005 , 05:27 PM







Lars,

I tried System.Diagnostics.Process as well and the same thing happened. A
notepad process starts but there is no corresponding window. could it be a
limitation of forms? I'm using a web form!

BrÃ*an

Reply With Quote
  #3  
Old   
Dubh
 
Posts: n/a

Default Re: running external Dos commands or programs - 04-20-2005 , 12:13 PM



OK, I'll do that but I will do the impersonation in code rather that the
web.config. I didn't get a chance to try the other code you sent yet due to
more pressing *issues*.

Thanks

BrÃ*an

"Lars-Inge Tønnessen [VJ# MVP]" wrote:

Quote:
From a ASP:NET application I would guess you would have to run the
application as a user with more rights than the standard "asp.net user". In
the web.config file do:

identity impersonate="true" username="login" password="password"

Regards,
Lars-Inge Tønnessen




Reply With Quote
  #4  
Old   
Dubh
 
Posts: n/a

Default Re: running external Dos commands or programs - 04-20-2005 , 01:12 PM



Using the folowing impersonation code:

System.Security.Principal.WindowsImpersonationCont ext impersonationContext;
impersonationContext
((System.Security.Principal.WindowsIdentity)get_Us er().get_Identity()).Impersonate();

//MY CODE HERE

impersonationContext.Undo();


Results are the same. NOTEPAD.EXE process starts but no output. I noticed on
the browser window that the status bar dispays "Downloading..." and the
progress bar is stuck at 50%.

I will try the other code now.

BrÃ*an


"Dubh" wrote:

Quote:
OK, I'll do that but I will do the impersonation in code rather that the
web.config. I didn't get a chance to try the other code you sent yet due to
more pressing *issues*.

Thanks

BrÃ*an

"Lars-Inge Tønnessen [VJ# MVP]" wrote:


From a ASP:NET application I would guess you would have to run the
application as a user with more rights than the standard "asp.net user". In
the web.config file do:

identity impersonate="true" username="login" password="password"

Regards,
Lars-Inge Tønnessen




Reply With Quote
  #5  
Old   
Dubh
 
Posts: n/a

Default Re: running external Dos commands or programs - 04-21-2005 , 02:14 PM



Not looking for output, just using this as a test to check why drive isn't
mapping. I'll try the code you sent and see if that works. My application
needs to give the client the ability to map to a Netware server, and rename a
file in that mapping that another esternal application process checks. That
process then does something depending on the existence or not of the
named/renamed file.
As I have over 250 netware servers I need a web application tha does
monitoring as well as other routine tasks such as this.

BrÃ*an

"Lars-Inge Tønnessen [VJ# MVP]" wrote:

Quote:
Results are the same. NOTEPAD.EXE process starts but no output. I noticed
on

What kind of output do you expect from Notepad in an ASP.NET application on
a server running as the "ASP.NET" user? (The ASP.NET user is not the logged
on user your using.)

What kind of an application do you build? What is the goal of your
web-application?


Regards,
Lars-Inge Tønnessen




Reply With Quote
  #6  
Old   
Dubh
 
Posts: n/a

Default Re: running external Dos commands or programs - 04-28-2005 , 08:52 AM



Lars,

this doesn't seem top want to work in j# .NET. I'm getting the following error

@dll.import required for native method

BrÃ*an

Reply With Quote
  #7  
Old   
Dubh
 
Posts: n/a

Default Re: running external Dos commands or programs - 05-06-2005 , 03:32 PM



Lars,

I just can't get this to work. I want to be able to do it from a web form
where the server name is entered in a text box and then a submit button maps
the drive. I then need to be able to rename a file in that drive mapping. Can
you recommend a good J#.NET book that might be of help?

Thanks

Brian

"Lars-Inge Tønnessen [VJ# MVP]" wrote:

Quote:
Sorry... I ment this line:

/** @attribute System.Runtime.InteropServices.DllImportAttribute( "mpr.dll")
*/
public static native System.UInt32 WNetAddConnection2A(
structure lpNetResource,
System.String lpPassword,
System.String UserName,
int dwFlags);

And this struct/structure:

/** @attribute
System.Runtime.InteropServices.StructLayout(System .Runtime.InteropServices.LayoutKind.Sequential)
*/
public class structure
{
public int Scope;
public int Type;
public int DisplayType;
public int Usage;
public System.String LocalName;
public System.String RemoteName;
public System.String Comment;
public System.String Provider;
}


Regards,
Lars-Inge Tønnessen




Reply With Quote
  #8  
Old   
Dubh
 
Posts: n/a

Default Re: running external Dos commands or programs - 05-11-2005 , 04:30 AM



I managed to get a directory listing again.

First of all I confirmed that the only way to list a remote share was by
inserting some impersonation code. However I alos had to sue the full path
instead of a drive mapping letter. It remains to be seen whether I will still
be able to rename a file using the UNC but I think I will.

Heres the snippet of code:

System.Security.Principal.WindowsImpersonationCont ext impersonationContext;
impersonationContext =
((System.Security.Principal.WindowsIdentity)get_Us er().get_Identity()).Impersonate();

this.list_files.get_Items().Clear();

structure str = new structure();
str.Type = 1;
int dwFlags = 1;
str.LocalName = "Z:";
str.RemoteName = this.t_server.get_Text();
str.Provider = null;
int ret = (int)this.WNetAddConnection2A( str, "myPassword",
".username.context",
dwFlags );


this.Label1.set_Text( "" + ret );

System.IO.DirectoryInfo dir = new
System.IO.DirectoryInfo(t_server.get_Text());




Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.