Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 2005 > Pro Visual Basic 2005
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Pro Visual Basic 2005 For advanced Visual Basic coders working in version 2005. Beginning-level questions will be redirected to other forums, including Beginning VB 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro Visual Basic 2005 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #1 (permalink)  
Old June 24th, 2009, 06:00 AM
Authorized User
 
Join Date: Nov 2005
Location: Bromsgrove, United Kingdom.
Posts: 41
Thanks: 6
Thanked 1 Time in 1 Post
Send a message via MSN to RobCarter
Unhappy Starting a console App from a vb.net windows app

Hi

I am a kinda VB.net noob so I am after as much constructive advice as possible for my issue:

I have a console app that was built by a contractor who has now left our company. It needs to be run every 7th working day.

Obviously, once the console app has finished its task it shuts down so I need a persistent application to begin the task again.

(it is at this point I would envisage people mentioning windows services but at this moment in time the mechanics of that is beyond my limited scope)

I have built a timer that looks at 7th working day and I now need for that windows app to open my console app. The exe opens but then I get a security permissions exception.

The code that invokes the console app is:

Code:
Imports LE22ExtractManager.clsDates
Imports System.Data.sqlclient
Imports System.Data.Sql
Imports System.Data
Imports Microsoft.VisualBasic.DateAndTime
Imports System.Diagnostics.Process
Namespace Medefeed
PublicClass clsMedeFeed
PublicSharedSub Check7thDay(ByRef MedeSwitch AsInteger)
Dim myFYst AsInteger = FiscalYearStartMonth.Apr
Dim dtpEnd AsString = Format(DateAdd(DateInterval.Day, -1, Today), "yyyyMMdd")
Dim dtpStart AsString = fiscalYear(myFYst, Today) & Right("00" & myFYst, 2) & "01"
Dim dDate AsString = Right("000" & Day(Today).ToString, 2) & "/" & Right("000" & Month(Today()).ToString, 2) & "/" & Year(Today()).ToString
Dim tot_rec AsInteger
Dim strConnection AsString = "Server=myserver;Database=Mydb;User ID=user;Password=pwd;Trusted_Connection=False;"
Dim sConn AsNew SqlConnection(strConnection)
Try
Dim sqlCommand AsNew SqlCommand("POPULATE_TIME_DIMENSION", sConn)
With sqlCommand
.CommandType = CommandType.StoredProcedure
.Parameters.AddWithValue("@dtstartdate", dtpStart)
.Parameters.AddWithValue("@dtenddate", dtpEnd)
EndWith
sConn.Open()
 
sqlCommand.ExecuteNonQuery()
Catch ex As Exception
Finally
sConn.Close()
EndTry
Dim sSql AsString = "select * from dim_time where "
sSql += "fulldatealternatekey = '" & dDate & "' and "
sSql += "numworkdays = 7"
Dim myDA As SqlDataAdapter = New SqlDataAdapter(sSql, sConn)
Dim myDs AsNew DataSet
Try
feedback("Started Building Medefeed")
sConn.Open()
myDA.Fill(myDs, "DateFinder")
tot_rec = myDs.Tables(0).Rows.Count
If tot_rec = 0 Then
Process.Start("\\server\f$\dir\dir\PatientCosting.exe")
MedeSwitch = 0
Else
MedeSwitch = 1
EndIf
'End If
Catch ex As Exception
Finally
myDA = Nothing
myDs = Nothing
sConn.Close()
EndTry
The exception that I get displays: System.Security.Permissions.SecurityPermission

If more information is needed I would be happy to clarify further.

Thanks for any help anyone can provide - I am totally stuck with this.

Rob
__________________
Rob Carter
  #2 (permalink)  
Old June 24th, 2009, 09:10 AM
Friend of Wrox
Points: 7,395, Level: 36
Points: 7,395, Level: 36 Points: 7,395, Level: 36 Points: 7,395, Level: 36
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Capital Federal, , Argentina.
Posts: 2,190
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi
Default

Hi there..

Which line throws the error?? the process start??

Are you sure that your program has enough permissions to run another one between a network???
__________________
HTH

Gonzalo


================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the
proof.
================================================== =========
The Following User Says Thank You to gbianchi For This Useful Post:
RobCarter (June 24th, 2009)
  #3 (permalink)  
Old June 24th, 2009, 09:40 AM
Authorized User
 
Join Date: Nov 2005
Location: Bromsgrove, United Kingdom.
Posts: 41
Thanks: 6
Thanked 1 Time in 1 Post
Send a message via MSN to RobCarter
Question

Its the process.start that generates the error - The exe file opens a console window but then the console app code is shown in the debugger with the error in the declarations:

Code:
Module mCosting
PrivateConst sSource = "\\Server\f$\dir\"
Private sDest AsString = "\\Server\f$\dir\sdir\" & Format(Today, "yyyyMMdd") & "\"
PrivateConst sFileSource = "\\correctfilepath"
PrivateConst sFileDest = "\\correctfilepath"
Public myFYst AsInteger = FiscalYearStartMonth.Apr
Public dtpEnd AsString = Format(DateAdd(DateInterval.Day, -1, Today), "yyyyMMdd")
Public dtpStart AsString = fiscalYear(myFYst, Today()) & Right("00" & myFYst, 2) & "01"
Sub Main()
'Console.WriteLine("Current user: " & WindowsIdentity.GetCurrent().Name)
Dim context AsNew WrapperImpersonationContext("domain", "user", "pwd")
context.Enter()
' Execute code under other uses context 
Console.WriteLine("Current user: " & WindowsIdentity.GetCurrent().Name)
GetSheetToUnprotect("Immunology", "myeloma")
'backup last months files
Archive(sSource, sDest)
runDTS("DTS_Export_OutpatientFeed", dtpStart, dtpEnd) '"20080401", "20090331")' 
runDTS("DTS_Export_InpatientFeed", dtpStart, dtpEnd) '"20080401", "20090331")' 
runDTS("DTS_Export_AlliedFeed", dtpStart, dtpEnd) '"20080401", "20090331")'
runDTS("DTS_Export_ProsthesisFeed", dtpStart, dtpEnd) '"20080401", "20090331")'
runDTS("DTS_Export_WastedProsthesisFeed", dtpStart, dtpEnd) '"20080401", "20090331")
runDTS("DTS_Export_RadiologyFeed", dtpStart, dtpEnd) '"20080401", "20090331")'
runDTS("DTS_Export_WardFeed", dtpStart, dtpEnd) '"20080401", "20090331")'
runDTS("DTS_Export_TheatreFeed", dtpStart, dtpEnd) '"20080401", "20090331")'
runDTS("DTS_Export_EndoscopyFeed", dtpStart, dtpEnd) '"20080401", "20090331")'
runDTS("DTS_Export_PathologyFeed", dtpStart, dtpEnd) '"20080401", "20090331") '
runDTS("DTS_Export_ROCSFeed", dtpStart, dtpEnd) '"20080401", "20090331")'
runDTS("DTS_Export_MacMillanFeed", dtpStart, dtpEnd) '"20080401", "20090331")'
runDTS("DTS_Export_ImmunologyFeed", dtpStart, dtpEnd) '"20080401", "20090331")'
runDTS("DTS_Export_NeuroPhysiologyFeed", dtpStart, dtpEnd) '"20080401", "20090331")'
Archive(sFileSource, sFileDest)
context.Leave()
Console.WriteLine("Current user: " & WindowsIdentity.GetCurrent().Name)
 
 
EndSub
EndModule
I have difficulty understanding the ins and outs of .net security, so no, I'm not sure about the security issue - can you point me to any guides that are sufficiently un-techie? Most that I have googled don't seem to apply.

If not could you give me an idea of search terms to achieve the best results?

Thanks for your reply.
__________________
Rob Carter
  #4 (permalink)  
Old June 24th, 2009, 09:43 AM
Authorized User
 
Join Date: Nov 2005
Location: Bromsgrove, United Kingdom.
Posts: 41
Thanks: 6
Thanked 1 Time in 1 Post
Send a message via MSN to RobCarter
Question

BTW the underlined section is where the debugger always lands. It points at the following function in its class:

Code:
 
Public Class clsDates
Public Enum FiscalYearStartMonth
Jan = 1
Feb = 2
Mar = 3
Apr = 4
May = 5
Jun = 6
Jul = 7
Aug = 8
Sep = 9
Oct = 10
Nov = 11
Dec = 12
End Enum
Shared Function fiscalYear(ByVal FYStartMonth As Integer, ByVal aDate As DateTime) As String
Dim theYear As Integer = aDate.Year
If aDate.Month >= FYStartMonth Then
'theYear += 1
Else
theYear -= 1
End If
Return theYear.ToString
End Function
End Class
__________________
Rob Carter
  #5 (permalink)  
Old June 24th, 2009, 10:20 AM
Authorized User
 
Join Date: Nov 2005
Location: Bromsgrove, United Kingdom.
Posts: 41
Thanks: 6
Thanked 1 Time in 1 Post
Send a message via MSN to RobCarter
Default

I actually sorted this out myself by going into the framework config and changing the permissions on our intranet zone to full trust.

Thanks for your questions gbianchi, they pointed me in the right direction.
__________________
Rob Carter
 


Thread Tools
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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert a VB.Net app to a web app? furjaw VB.NET 3 September 24th, 2007 01:27 PM
Obfuscation..of windows based vb.net app. causes t tciinc General .NET 1 July 10th, 2007 09:13 PM
Executing vb.net console app via report services rickyc1 BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 2 March 31st, 2006 03:56 AM
What Windows can VB .NET App run on ocarroll General .NET 6 February 27th, 2006 08:14 AM
DateTimePicker in Windows App Form VB.NET LaFeverMF VB.NET 2002/2003 Basics 1 February 13th, 2004 09:50 AM



All times are GMT -4. The time now is 03:42 AM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.