473,695 Members | 2,039 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Unable to execute Shell command in ASP.NET to print using DOS

Hi,

I have an ASP.NET application using VB.NET.I am sending a DOS command to a
machine on the network to print a file.
This is achieved using xp_cmdshell
Dim str As String = "xp_cmdshel l ""type " & nwkfilepath & " > " &
pPrinterName & " """

and str is executed in the MSSQL Master database which has got permissions
to do it.
Problem Statement
*************** ***
The same functionality could not be achieved using shell or diagnostics
namespace.The user ASP.NET has
already been given admin rights(as this is the user that executes an aspx
page)

Any help would be highly appreciated as this has snowballed into a major
production issue.
Regards

Kartik Ganesan
Jul 21 '05 #1
4 9890
I believe the xp_cmdshell is using the permissions of the user that the SQL
Server itself runs under.

Also, are you getting an error??

Jeff

"Kartik" <Ka****@discuss ions.microsoft. com> wrote in message
news:A0******** *************** ***********@mic rosoft.com...
Hi,

I have an ASP.NET application using VB.NET.I am sending a DOS command to a
machine on the network to print a file.
This is achieved using xp_cmdshell
Dim str As String = "xp_cmdshel l ""type " & nwkfilepath & " > " &
pPrinterName & " """

and str is executed in the MSSQL Master database which has got permissions
to do it.
Problem Statement
*************** ***
The same functionality could not be achieved using shell or diagnostics
namespace.The user ASP.NET has
already been given admin rights(as this is the user that executes an aspx
page)

Any help would be highly appreciated as this has snowballed into a major
production issue.
Regards

Kartik Ganesan

Jul 21 '05 #2
No am not getting any error..In fact
this is the code

Dim aa As Integer
aa = Shell("C:\XYZ\A BC.bat", AppWinStyle.Max imizedFocus)

and when i run in debug mode I get a value for aa..which is the process id.

ABC.bat contains the following lines

type C:\abc\myfile.K AR > \\mynetworkmach ine\zebra234

where \\mynetworkmach ine\zebra234 has been provided network share..

I mean ...this works
type C:\abc\myfile.K AR > \\mynetworkmach ine\zebra234

when i execute this through dos.

Thanks in Anticipation

Kartik


"Jeff Dillon" wrote:
I believe the xp_cmdshell is using the permissions of the user that the SQL
Server itself runs under.

Also, are you getting an error??

Jeff

"Kartik" <Ka****@discuss ions.microsoft. com> wrote in message
news:A0******** *************** ***********@mic rosoft.com...
Hi,

I have an ASP.NET application using VB.NET.I am sending a DOS command to a
machine on the network to print a file.
This is achieved using xp_cmdshell
Dim str As String = "xp_cmdshel l ""type " & nwkfilepath & " > " &
pPrinterName & " """

and str is executed in the MSSQL Master database which has got permissions
to do it.
Problem Statement
*************** ***
The same functionality could not be achieved using shell or diagnostics
namespace.The user ASP.NET has
already been given admin rights(as this is the user that executes an aspx
page)

Any help would be highly appreciated as this has snowballed into a major
production issue.
Regards

Kartik Ganesan


Jul 21 '05 #3
Yes, a permissions issue most likely

Jeff
"kartik" <ka****@discuss ions.microsoft. com> wrote in message
news:EB******** *************** ***********@mic rosoft.com...
No am not getting any error..In fact
this is the code

Dim aa As Integer
aa = Shell("C:\XYZ\A BC.bat", AppWinStyle.Max imizedFocus)

and when i run in debug mode I get a value for aa..which is the process id.
ABC.bat contains the following lines

type C:\abc\myfile.K AR > \\mynetworkmach ine\zebra234

where \\mynetworkmach ine\zebra234 has been provided network share..

I mean ...this works
type C:\abc\myfile.K AR > \\mynetworkmach ine\zebra234

when i execute this through dos.

Thanks in Anticipation

Kartik


"Jeff Dillon" wrote:
I believe the xp_cmdshell is using the permissions of the user that the SQL Server itself runs under.

Also, are you getting an error??

Jeff

"Kartik" <Ka****@discuss ions.microsoft. com> wrote in message
news:A0******** *************** ***********@mic rosoft.com...
Hi,

I have an ASP.NET application using VB.NET.I am sending a DOS command to a machine on the network to print a file.
This is achieved using xp_cmdshell
Dim str As String = "xp_cmdshel l ""type " & nwkfilepath & " > " & pPrinterName & " """

and str is executed in the MSSQL Master database which has got permissions to do it.
Problem Statement
*************** ***
The same functionality could not be achieved using shell or diagnostics namespace.The user ASP.NET has
already been given admin rights(as this is the user that executes an aspx page)

Any help would be highly appreciated as this has snowballed into a major production issue.
Regards

Kartik Ganesan


Jul 21 '05 #4
Actually no.I can execute file creations commands...more likely a
network issue.The following code from
http://www.thescarms.com/dotNet/Process.asp executes perfectly
fine.But when I execute my code it fails with exitcode = -1.

Sample Code from http://www.thescarms.com/dotNet/Process.asp
*************** **************

Dim myProcess As Process = New Process()
Dim s As String
Dim outfile As String = Application.Sta rtupPath & "\Output.tx t"
'
' Get the System path.
'
Dim sysFolder As String =
System.Environm ent.GetFolderPa th(Environment. SpecialFolder.S ystem)
'
' Createe the command line.
'
myProcess.Start Info.FileName = "cmd.exe"
myProcess.Start Info.Arguments = "/C cd " & sysFolder & _
" && dir *.com >> " & Chr(34) & outfile & Chr(34) & " && exit"
'
' Start the process in a hidden window.
'
myProcess.Start Info.WindowStyl e = ProcessWindowSt yle.Hidden
myProcess.Start Info.CreateNoWi ndow = True
myProcess.Start ()
'
' Kill the process if it doesn't finish in one minute.
'
myProcess.WaitF orExit(1000)
If Not myProcess.HasEx ited Then
myProcess.Kill( )
End If
'
' Show the results.
'
MessageBox.Show ("The 'dir' command window was " & _
"closed at: " & myProcess.ExitT ime & "." &
System.Environm ent.NewLine & _
"Exit Code: " & myProcess.ExitC ode)

myProcess.Close ()

*************** *************

My Code
*************** *************** *************** *************** *************** ****

Dim myProcess As Process = New Process()
Dim s As String
Dim outfile As String = "\\cafe500\zebr a234"
'
' Get the System path.
'
Dim sysFolder As String =
System.Environm ent.GetFolderPa th(Environment. SpecialFolder.S ystem)
'
' Createe the command line.
'
myProcess.Start Info.FileName = "cmd.exe"
'myProcess.Star tInfo.Arguments = "/C cd " & sysFolder & " &&
dir *.com >> " & Chr(34) & outfile & Chr(34) & " && exit"
myProcess.Start Info.Arguments = "/C type C:\\239301U2.KA R >
\\xyz\zebra234"
'
' Start the process in a hidden window.
'
myProcess.Start Info.WindowStyl e = ProcessWindowSt yle.Hidden
myProcess.Start Info.CreateNoWi ndow = True
myProcess.Start ()
'
' Kill the process if it doesn't finish in one minute.
'
myProcess.WaitF orExit(1000)
If Not myProcess.HasEx ited Then
myProcess.Kill( )
End If
'
' Show the results.
'
Response.Write( "The 'dir' command window was " & _
"closed at: " & myProcess.ExitT ime & "." &
System.Environm ent.NewLine & _
"Exit Code: " & myProcess.ExitC ode)

myProcess.Close ()

*************** *************** *************** *************** *************** ****
I donno why it fails ..any help would be highly appreciated.
Kartik
"Jeff Dillon" <je**@removeeme rgencyreporting .com> wrote in message news:<uO******* *******@TK2MSFT NGP10.phx.gbl>. ..
Yes, a permissions issue most likely

Jeff
"kartik" <ka****@discuss ions.microsoft. com> wrote in message
news:EB******** *************** ***********@mic rosoft.com...
No am not getting any error..In fact
this is the code

Dim aa As Integer
aa = Shell("C:\XYZ\A BC.bat", AppWinStyle.Max imizedFocus)

and when i run in debug mode I get a value for aa..which is the process

id.

ABC.bat contains the following lines

type C:\abc\myfile.K AR > \\mynetworkmach ine\zebra234

where \\mynetworkmach ine\zebra234 has been provided network share..

I mean ...this works
type C:\abc\myfile.K AR > \\mynetworkmach ine\zebra234

when i execute this through dos.

Thanks in Anticipation

Kartik


"Jeff Dillon" wrote:
I believe the xp_cmdshell is using the permissions of the user that the SQL Server itself runs under.

Also, are you getting an error??

Jeff

"Kartik" <Ka****@discuss ions.microsoft. com> wrote in message
news:A0******** *************** ***********@mic rosoft.com...
> Hi,
>
> I have an ASP.NET application using VB.NET.I am sending a DOS command to a > machine on the network to print a file.
> This is achieved using xp_cmdshell
>
>
> Dim str As String = "xp_cmdshel l ""type " & nwkfilepath & " > " & > pPrinterName & " """
>
> and str is executed in the MSSQL Master database which has got permissions > to do it.
>
>
> Problem Statement
> *************** ***
> The same functionality could not be achieved using shell or diagnostics > namespace.The user ASP.NET has
> already been given admin rights(as this is the user that executes an aspx > page)
>
>
>
> Any help would be highly appreciated as this has snowballed into a major > production issue.
>
>
> Regards
>
> Kartik Ganesan

Jul 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
11013
by: Valentine Kouznetsov | last post by:
Hi, simple question, how to execute command in current shell, not in subshell? Example. I have environment variable A=aaa and need to invoke shell (sh) script which will do something with A. If I do os.system() then sub-shell will setup A and execute my script there leaving A in parent shell untouched. Thanks,
0
296
by: Kartik | last post by:
Hi, I have an ASP.NET application using VB.NET.I am sending a DOS command to a machine on the network to print a file. This is achieved using xp_cmdshell Dim str As String = "xp_cmdshell ""type " & nwkfilepath & " > " & pPrinterName & " """
4
413
by: Kartik | last post by:
Hi, I have an ASP.NET application using VB.NET.I am sending a DOS command to a machine on the network to print a file. This is achieved using xp_cmdshell Dim str As String = "xp_cmdshell ""type " & nwkfilepath & " > " & pPrinterName & " """
7
2985
by: spec | last post by:
Hi all, I know nothing about Python. What I need to do is to get a Python script to execute a local shell script. I do not need any output. What would be th eeasiest way to accomplish this? Thanks!
9
78330
by: sohan | last post by:
Hi, I want to know how to connect and execute a db2 query from inside a UNIX shell script. Details: We have a unix shell script. We need to execute multiple db2 sql queries from this shell script and export the result to a file. Any code snippet on this will be helpful.
6
8160
Cintury
by: Cintury | last post by:
Hi all, I've developed a mobile application for windows mobile 5.0 that has been in use for a while (1 year and a couple of months). It was developed in visual studios 2005 with a back-end sql server mobile ce database. Until recently I was synching everything thru a com port serial cable. The devices would connect to the computer thru activesync and are able to acquire an internet connection. The sync for the program occurs thru a website...
1
3551
by: raocheng | last post by:
Please see the following code. Suppose I have many shell commands to be executed. And I don't want to fork a sub shell for each command(eg: status,output = commands.getstatusoutput(cmd)) because it is too expensive. I want to use only one sub shell to execute all these commands and want to get each command's output. How can I accomplish this task ? Thanks in advance. =========================================== #!/usr/bin/env python
7
6232
by: Samuel A. Falvo II | last post by:
I have a shell script script.sh that launches a Java process in the background using the &-operator, like so: #!/bin/bash java ... arguments here ... & In my Python code, I want to invoke this shell script using the Subprocess module. Here is my code: def resultFromRunning_(command):
1
5219
by: mlaris | last post by:
Howdy, We are experiencing a bizarre problem under Linux attempting to restore a DB2 database. The backup was created on this machine, and is being restored to the same machine, but changing the name of the database, and redirecting the tablespaces. The system is running DB2 Express C V9.5 and RHEL5 with latest updates The restore commands we are trying to run are as follows: RESTORE DATABASE CARDS FROM "/opt/rccs/data/backups"...
0
8631
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9115
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8984
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8825
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7661
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6491
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5839
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4340
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3003
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.