Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 2005 > Pro Visual Basic 2005
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old June 24th, 2009, 05:00 AM
Authorized User
Join Date: Nov 2005
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


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:

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)
Dim sqlCommand AsNew SqlCommand("POPULATE_TIME_DIMENSION", sConn)
With sqlCommand
.CommandType = CommandType.StoredProcedure
.Parameters.AddWithValue("@dtstartdate", dtpStart)
.Parameters.AddWithValue("@dtenddate", dtpEnd)
Catch ex As Exception
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
feedback("Started Building Medefeed")
myDA.Fill(myDs, "DateFinder")
tot_rec = myDs.Tables(0).Rows.Count
If tot_rec = 0 Then
MedeSwitch = 0
MedeSwitch = 1
'End If
Catch ex As Exception
myDA = Nothing
myDs = Nothing
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 Carter
Old June 24th, 2009, 08:10 AM
Friend of Wrox
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
Send a message via MSN to gbianchi

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???


================================================== =========
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 :
================================================== =========
I know that CVS was evil, and now i got the
================================================== =========
The Following User Says Thank You to gbianchi For This Useful Post:
RobCarter (June 24th, 2009)
Old June 24th, 2009, 08:40 AM
Authorized User
Join Date: Nov 2005
Posts: 41
Thanks: 6
Thanked 1 Time in 1 Post
Send a message via MSN to RobCarter

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:

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")
' 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)
Console.WriteLine("Current user: " & WindowsIdentity.GetCurrent().Name)
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
Old June 24th, 2009, 08:43 AM
Authorized User
Join Date: Nov 2005
Posts: 41
Thanks: 6
Thanked 1 Time in 1 Post
Send a message via MSN to RobCarter

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

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
theYear -= 1
End If
Return theYear.ToString
End Function
End Class
Rob Carter
Old June 24th, 2009, 09:20 AM
Authorized User
Join Date: Nov 2005
Posts: 41
Thanks: 6
Thanked 1 Time in 1 Post
Send a message via MSN to RobCarter

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

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 12:27 PM
Obfuscation..of windows based vb.net app. causes t tciinc General .NET 1 July 10th, 2007 08: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

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.