.Net Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - More.Net Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 23rd, 2012, 09:42 AM
jethro45 jethro45 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 2 jethro45 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m 54 sec
Reputation Power: 0
Code behind runs in VS 2010 but not when published on IIS

I have an ASP.NET site I built for our users to map a network printer. When I test it, it maps the printer without any probelms. When I publish it to IIS, it acts like it's going to run, but never tries to map it. Any suggestions or answers will be greatly appreciated. I have checked all the permissions, I have tried it as a web app and a web site, I have tried to publish both and I have tried to copy and paste the folders in the root folder. I have added references to the Microsoft.Powershell.XXXX. I have changed it from "CodeBehind" to "CodeFile" and I have changed the "AutoEventWireup" to "true". There are no errors in the event log and none on screen. It clears the fields, like it should at the end of the code and that's it. I am not sure what else to do now. Thank you.

[code}

Imports System.Collections.ObjectModel
Imports System.Management.Automation
Imports System.Management.Automation.Runspaces
Imports System.Text
Imports System.IO





Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click

If DropDownList1.Text = "ABCD" Then
Label1.Text = " \\ServerB"
End If

If DropDownList1.Text = "EFGH" Then
Label1.Text = " \\ServerC"
End If

If DropDownList1.Text = "IJKL" Then
Label1.Text = " \\ServerD"
End If

If DropDownList1.Text = "MNOP" Then
Label1.Text = " \\ServerE"
End If

'Maps the printer from the selections above.
Label2.Text = "rundll32 printui.dll,PrintUIEntry /q /in /c\\"
Label3.Text = " /n"
Label4.Text = Label2.Text & Label3.Text & Label1.Text & "\" & TextBox3.Text

'Sets it as default
If RadioButton1.Checked = True Then
Label5.Text = Label2.Text & " /y" & Label1.Text & "\" & TextBox3.Text
End If

'Sets it for all users
If RadioButton2.Checked = True Then
Label6.Text = Label2.Text & " /ga" & Label1.Text & "\" & TextBox3.Text
End If

'Powershell commands
Dim printerserver As String = CStr(Label1.Text)
Dim printer As String = CStr(TextBox3.Text)
Dim printcmd As String = CStr(Label2.Text)
Dim networkpath As String = CStr(Label4.Text)
Dim networkdefault As String = CStr(Label5.Text)
Dim allusers As String = CStr(Label6.Text)



Shell(networkpath, AppWinStyle.Hide)


Shell(networkdefault, AppWinStyle.Hide)


Shell(allusers, AppWinStyle.Hide)


'Clears the screen so that a new printer can be added.
TextBox3.Text = ""
RadioButton1.Checked = False
RadioButton2.Checked = False
RadioButton3.Checked = False
RadioButton4.Checked = False
DropDownList1.Text = ""


End Sub




<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="WebApplication1.WebForm1" %>

[code]

Reply With Quote
  #2  
Old October 23rd, 2012, 09:36 PM
f'lar's Avatar
f'lar f'lar is offline
ASP.Net MVP
Dev Shed Specialist (4000 - 4499 posts)
 
Join Date: Aug 2003
Location: WI
Posts: 4,378 f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 2 Days 11 h 4 m 57 sec
Reputation Power: 1509
Send a message via Google Talk to f'lar
I see that the "magic" happens in a series of three calls to the Shell() function. You have the mistaken notion that this function is running on the end user's computer, where the browser this. That is wrong. Your Shell() calls run on your web server. The code seems to work in Visual Studio because in the case, the server and browser are on the same computer.

So the question remains, how do you get this code to run from the web browser? The answer is that you don't. Web browsers are designed as sandboxes for web content specifically to prevent running this kind of arbitrary code on the local system. There is now work-around that will allow you to use the Shell() command the way you want. Otherwise, for example, everyone's desktop printer would collect the same kind of junk a public fax machine attracts.

So what can you do? Unfortunately, you're only option if you keep going down the same path is to build a browser add on, and that's not likely to gain much traction from your users or your IT dept. Thankfully, there is a feature built into Windows Print Servers that allows them to publish printers via the web. You should be able to activate this feature in IIS, find the address for each printer, and then provide a link your users can click on. And that's the best you'll likely be able to do.
__________________
Primary Forum: .Net Development
Holy cow, I'm now an ASP.Net MVP!

[Moving to ASP.Net] | [.Net Dos and Don't for VB6 Programmers]

http://twitter.com/jcoehoorn

Reply With Quote
  #3  
Old October 26th, 2012, 01:06 AM
jethro45 jethro45 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2012
Posts: 2 jethro45 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m 54 sec
Reputation Power: 0
Is there any other way around it? What about building a text box that inputs the code, and from there the powershell is called to run?

Reply With Quote
  #4  
Old October 29th, 2012, 10:34 PM
f'lar's Avatar
f'lar f'lar is offline
ASP.Net MVP
Dev Shed Specialist (4000 - 4499 posts)
 
Join Date: Aug 2003
Location: WI
Posts: 4,378 f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 2 Days 11 h 4 m 57 sec
Reputation Power: 1509
Send a message via Google Talk to f'lar
Quote:
Originally Posted by jethro45
Is there any other way around it? What about building a text box that inputs the code, and from there the powershell is called to run?

You can't call powershell from the browser without a custom add-on. Period. Again, preventing this kind of access is a core part of what browsers do.

Reply With Quote
  #5  
Old December 12th, 2012, 12:24 AM
gtopawb gtopawb is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 2 gtopawb User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 19 m 35 sec
Reputation Power: 0
Ugg Fox Fur Boots

Is there any other way around it?What about building a text box that inputs the code, and from there the powershell is called to run?

Reply With Quote
  #6  
Old December 16th, 2012, 10:23 PM
f'lar's Avatar
f'lar f'lar is offline
ASP.Net MVP
Dev Shed Specialist (4000 - 4499 posts)
 
Join Date: Aug 2003
Location: WI
Posts: 4,378 f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level)f'lar User rank is General 8th Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 2 Days 11 h 4 m 57 sec
Reputation Power: 1509
Send a message via Google Talk to f'lar
That won't work. You just can't start the powershell process. No way, no how. End of story.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - More.Net Development > Code behind runs in VS 2010 but not when published on IIS

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap