Imperonsate?

  • Thread starter Thread starter Joshua Campbell
  • Start date Start date
J

Joshua Campbell

I have a program that I have written in VB.NET that parses a file out,
places data in Excel fields, and then prints out the Excel to Distiller so I
can create a PDF. I have this as a scheduled task. This works fine
whenever I have the machine logged in and locked. However, if I do not have
the machine logged in, then I get printer errors. So, I am thinking that if
I were to make the program impersonate the user, then the printers will work
correctly. So, how do I impersonate a user?



Thanks.

Joshua
 
Hi Joshua,

When set the schedule task in the windows interface, you may set the
account to run the schedule task.
You may do by following steps.
1. Navigated to Start/Control Panel/Shceduled Tasks/Add Scheduled Tasks
2. Click Next
3. Click Browse button to select the program you want to schedule.
4. Schedule the task in one mode[Daily, Weekly,.....], here I select "When
I log on", click next.
5. Input the Username and account at which you want to run your task.
Click Next.
6. Click finish.

You may have a try and let me the result.



Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


--------------------
 
Even then it does not print correctly unless I have the server logged in as
the user.

Joshua


Peter Huang said:
Hi Joshua,

When set the schedule task in the windows interface, you may set the
account to run the schedule task.
You may do by following steps.
1. Navigated to Start/Control Panel/Shceduled Tasks/Add Scheduled Tasks
2. Click Next
3. Click Browse button to select the program you want to schedule.
4. Schedule the task in one mode[Daily, Weekly,.....], here I select "When
I log on", click next.
5. Input the Username and account at which you want to run your task.
Click Next.
6. Click finish.

You may have a try and let me the result.



Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


--------------------
Reply-To: "Joshua Campbell" <[email protected]>
From: "Joshua Campbell" <[email protected]>
Subject: Imperonsate?
Date: Fri, 22 Aug 2003 08:10:04 -0400
Lines: 17
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.languages.vb
NNTP-Posting-Host: 205.152.115.197
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:129660
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

I have a program that I have written in VB.NET that parses a file out,
places data in Excel fields, and then prints out the Excel to Distiller
so
I
can create a PDF. I have this as a scheduled task. This works fine
whenever I have the machine logged in and locked. However, if I do not have
the machine logged in, then I get printer errors. So, I am thinking that if
I were to make the program impersonate the user, then the printers will work
correctly. So, how do I impersonate a user?



Thanks.

Joshua
 
Hi Joshua,

Could you tell me in what account did you run your program in?
Here is my code to test. It will be compiled as test.exe.
Private Sub Form_Load()
Dim ex As Excel.Application
Set ex = New Application
ex.Workbooks.Open "c:\a.xls"
ex.Workbooks(1).PrintOut
ex.Quit
Set ex = Nothing
MsgBox "a"
End Sub

I have try to schedule the test.exe at a time Daily or at system startup.
I can not reproduce the problem. When I am not login to the system, the
task will be executed.
The account I set in the task schedule run as is an account in
administrators groups.

You may have a try and let me know the result.
I would like you can post the code you test on your machine so that I can
reproduce the problem.
In addition, which account did you run your task in?


Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
--------------------
Reply-To: "Joshua Campbell" <[email protected]>
From: "Joshua Campbell" <[email protected]>
References: <[email protected]>
Subject: Re: Imperonsate?
Date: Mon, 25 Aug 2003 11:26:05 -0400
Lines: 77
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.languages.vb
NNTP-Posting-Host: 205.152.115.197
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:130241
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

Even then it does not print correctly unless I have the server logged in as
the user.

Joshua


Peter Huang said:
Hi Joshua,

When set the schedule task in the windows interface, you may set the
account to run the schedule task.
You may do by following steps.
1. Navigated to Start/Control Panel/Shceduled Tasks/Add Scheduled Tasks
2. Click Next
3. Click Browse button to select the program you want to schedule.
4. Schedule the task in one mode[Daily, Weekly,.....], here I select "When
I log on", click next.
5. Input the Username and account at which you want to run your task.
Click Next.
6. Click finish.

You may have a try and let me the result.



Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


--------------------
Reply-To: "Joshua Campbell" <[email protected]>
From: "Joshua Campbell" <[email protected]>
Subject: Imperonsate?
Date: Fri, 22 Aug 2003 08:10:04 -0400
Lines: 17
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.languages.vb
NNTP-Posting-Host: 205.152.115.197
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:129660
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

I have a program that I have written in VB.NET that parses a file out,
places data in Excel fields, and then prints out the Excel to Distiller
so
I
can create a PDF. I have this as a scheduled task. This works fine
whenever I have the machine logged in and locked. However, if I do not have
the machine logged in, then I get printer errors. So, I am thinking
that
if
I were to make the program impersonate the user, then the printers will work
correctly. So, how do I impersonate a user?



Thanks.

Joshua
 
The account that is being used is a domain account that is also a local
administrator of that machine. The print program that you gave would
probably work as a scheduled task. But, let me attach the code below so you
can see exactly what I'm doing.

Dim rngPrint As Excel.Range
Dim shp As Excel.Shape
Dim szAddress As String
Try
If TypeOf xlbook.ActiveSheet Is Excel.Worksheet Then
With xlbook.ActiveSheet
If Len(xlsheet.PageSetup.PrintArea) Then
szAddress = xlsheet.PageSetup.PrintArea Else szAddress =
xlsheet.UsedRange.Address
End With
rngPrint = xlsheet.Range(szAddress)
With rngPrint

..CopyPicture(Appearance:=Excel.XlPictureAppearance.xlScreen,
Format:=Excel.XlCopyPictureFormat.xlBitmap)
With .Parent

rngPrint.Worksheet.Paste(Destination:=rngPrint)
xlsheet.Application.ActivePrinter =
config.AppSettings("PrinterName") 'Adobe Distiller

xlsheet.Application.ActiveWindow.SelectedSheets.PrintOut(Copies:=1,
Collate:=True)
End With
End With
End If
Catch e2 As Exception
EventLog.WriteEntry("Invoices to PDF Application",
"There was an error printing/saving the PDF." & vbCrLf & e2.Message,
EventLogEntryType.Error, 1, 1)
bErrors = True
End Try

So, in this example, it is putting in the background image and then printing
off to a PDF. I am using Adobe Distiller 5.0 to accomplish this.

Joshua



Peter Huang said:
Hi Joshua,

Could you tell me in what account did you run your program in?
Here is my code to test. It will be compiled as test.exe.
Private Sub Form_Load()
Dim ex As Excel.Application
Set ex = New Application
ex.Workbooks.Open "c:\a.xls"
ex.Workbooks(1).PrintOut
ex.Quit
Set ex = Nothing
MsgBox "a"
End Sub

I have try to schedule the test.exe at a time Daily or at system startup.
I can not reproduce the problem. When I am not login to the system, the
task will be executed.
The account I set in the task schedule run as is an account in
administrators groups.

You may have a try and let me know the result.
I would like you can post the code you test on your machine so that I can
reproduce the problem.
In addition, which account did you run your task in?


Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
--------------------
Reply-To: "Joshua Campbell" <[email protected]>
From: "Joshua Campbell" <[email protected]>
References: <[email protected]>
Subject: Re: Imperonsate?
Date: Mon, 25 Aug 2003 11:26:05 -0400
Lines: 77
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.languages.vb
NNTP-Posting-Host: 205.152.115.197
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:130241
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

Even then it does not print correctly unless I have the server logged in as
the user.

Joshua


Peter Huang said:
Hi Joshua,

When set the schedule task in the windows interface, you may set the
account to run the schedule task.
You may do by following steps.
1. Navigated to Start/Control Panel/Shceduled Tasks/Add Scheduled Tasks
2. Click Next
3. Click Browse button to select the program you want to schedule.
4. Schedule the task in one mode[Daily, Weekly,.....], here I select "When
I log on", click next.
5. Input the Username and account at which you want to run your task.
Click Next.
6. Click finish.

You may have a try and let me the result.



Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
From: "Joshua Campbell" <[email protected]>
Subject: Imperonsate?
Date: Fri, 22 Aug 2003 08:10:04 -0400
Lines: 17
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.languages.vb
NNTP-Posting-Host: 205.152.115.197
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:129660
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

I have a program that I have written in VB.NET that parses a file out,
places data in Excel fields, and then prints out the Excel to
Distiller
so
I
can create a PDF. I have this as a scheduled task. This works fine
whenever I have the machine logged in and locked. However, if I do not
have
the machine logged in, then I get printer errors. So, I am thinking that
if
I were to make the program impersonate the user, then the printers will
work
correctly. So, how do I impersonate a user?



Thanks.

Joshua
 
Hi Joshua,

You may try to modify your code to print to a common printer to see if the
problem exist.
I think when you print to a adobe distiller printer, it will open a dialog
for you to save to a pdf file.


Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
--------------------
Reply-To: "Joshua Campbell" <[email protected]>
From: "Joshua Campbell" <[email protected]>
References: <[email protected]>
<[email protected]>
Subject: Re: Imperonsate?
Date: Tue, 26 Aug 2003 07:49:55 -0400
Lines: 186
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.languages.vb
NNTP-Posting-Host: 205.152.115.197
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:130545
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

The account that is being used is a domain account that is also a local
administrator of that machine. The print program that you gave would
probably work as a scheduled task. But, let me attach the code below so you
can see exactly what I'm doing.

Dim rngPrint As Excel.Range
Dim shp As Excel.Shape
Dim szAddress As String
Try
If TypeOf xlbook.ActiveSheet Is Excel.Worksheet Then
With xlbook.ActiveSheet
If Len(xlsheet.PageSetup.PrintArea) Then
szAddress = xlsheet.PageSetup.PrintArea Else szAddress =
xlsheet.UsedRange.Address
End With
rngPrint = xlsheet.Range(szAddress)
With rngPrint

.CopyPicture(Appearance:=Excel.XlPictureAppearance.xlScreen,
Format:=Excel.XlCopyPictureFormat.xlBitmap)
With .Parent

rngPrint.Worksheet.Paste(Destination:=rngPrint)
xlsheet.Application.ActivePrinter =
config.AppSettings("PrinterName") 'Adobe Distiller

xlsheet.Application.ActiveWindow.SelectedSheets.PrintOut(Copies:=1,
Collate:=True)
End With
End With
End If
Catch e2 As Exception
EventLog.WriteEntry("Invoices to PDF Application",
"There was an error printing/saving the PDF." & vbCrLf & e2.Message,
EventLogEntryType.Error, 1, 1)
bErrors = True
End Try

So, in this example, it is putting in the background image and then printing
off to a PDF. I am using Adobe Distiller 5.0 to accomplish this.

Joshua



Peter Huang said:
Hi Joshua,

Could you tell me in what account did you run your program in?
Here is my code to test. It will be compiled as test.exe.
Private Sub Form_Load()
Dim ex As Excel.Application
Set ex = New Application
ex.Workbooks.Open "c:\a.xls"
ex.Workbooks(1).PrintOut
ex.Quit
Set ex = Nothing
MsgBox "a"
End Sub

I have try to schedule the test.exe at a time Daily or at system startup.
I can not reproduce the problem. When I am not login to the system, the
task will be executed.
The account I set in the task schedule run as is an account in
administrators groups.

You may have a try and let me know the result.
I would like you can post the code you test on your machine so that I can
reproduce the problem.
In addition, which account did you run your task in?


Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
--------------------
Reply-To: "Joshua Campbell" <[email protected]>
From: "Joshua Campbell" <[email protected]>
References: <[email protected]>
Subject: Re: Imperonsate?
Date: Mon, 25 Aug 2003 11:26:05 -0400
Lines: 77
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.languages.vb
NNTP-Posting-Host: 205.152.115.197
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:130241
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

Even then it does not print correctly unless I have the server logged in as
the user.

Joshua


Hi Joshua,

When set the schedule task in the windows interface, you may set the
account to run the schedule task.
You may do by following steps.
1. Navigated to Start/Control Panel/Shceduled Tasks/Add Scheduled Tasks
2. Click Next
3. Click Browse button to select the program you want to schedule.
4. Schedule the task in one mode[Daily, Weekly,.....], here I select "When
I log on", click next.
5. Input the Username and account at which you want to run your task.
Click Next.
6. Click finish.

You may have a try and let me the result.



Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
From: "Joshua Campbell" <[email protected]>
Subject: Imperonsate?
Date: Fri, 22 Aug 2003 08:10:04 -0400
Lines: 17
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.languages.vb
NNTP-Posting-Host: 205.152.115.197
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:129660
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

I have a program that I have written in VB.NET that parses a file out,
places data in Excel fields, and then prints out the Excel to Distiller
so
I
can create a PDF. I have this as a scheduled task. This works fine
whenever I have the machine logged in and locked. However, if I do not
have
the machine logged in, then I get printer errors. So, I am thinking that
if
I were to make the program impersonate the user, then the printers will
work
correctly. So, how do I impersonate a user?



Thanks.

Joshua
 
No, it does not prompt with a save dialog. That is a setting in Distiller.
Please keep in mind that the program works perfectly well and
programmatically generates 1000's of PDFs a day without a problem, except
that I have to be logged in in order for the print to work.


Peter Huang said:
Hi Joshua,

You may try to modify your code to print to a common printer to see if the
problem exist.
I think when you print to a adobe distiller printer, it will open a dialog
for you to save to a pdf file.


Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
--------------------
Reply-To: "Joshua Campbell" <[email protected]>
From: "Joshua Campbell" <[email protected]>
References: <[email protected]>
<[email protected]>
Subject: Re: Imperonsate?
Date: Tue, 26 Aug 2003 07:49:55 -0400
Lines: 186
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.languages.vb
NNTP-Posting-Host: 205.152.115.197
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:130545
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

The account that is being used is a domain account that is also a local
administrator of that machine. The print program that you gave would
probably work as a scheduled task. But, let me attach the code below so you
can see exactly what I'm doing.

Dim rngPrint As Excel.Range
Dim shp As Excel.Shape
Dim szAddress As String
Try
If TypeOf xlbook.ActiveSheet Is Excel.Worksheet Then
With xlbook.ActiveSheet
If Len(xlsheet.PageSetup.PrintArea) Then
szAddress = xlsheet.PageSetup.PrintArea Else szAddress =
xlsheet.UsedRange.Address
End With
rngPrint = xlsheet.Range(szAddress)
With rngPrint

.CopyPicture(Appearance:=Excel.XlPictureAppearance.xlScreen,
Format:=Excel.XlCopyPictureFormat.xlBitmap)
With .Parent

rngPrint.Worksheet.Paste(Destination:=rngPrint)
xlsheet.Application.ActivePrinter =
config.AppSettings("PrinterName") 'Adobe Distiller

xlsheet.Application.ActiveWindow.SelectedSheets.PrintOut(Copies:=1,
Collate:=True)
End With
End With
End If
Catch e2 As Exception
EventLog.WriteEntry("Invoices to PDF Application",
"There was an error printing/saving the PDF." & vbCrLf & e2.Message,
EventLogEntryType.Error, 1, 1)
bErrors = True
End Try

So, in this example, it is putting in the background image and then printing
off to a PDF. I am using Adobe Distiller 5.0 to accomplish this.

Joshua



Peter Huang said:
Hi Joshua,

Could you tell me in what account did you run your program in?
Here is my code to test. It will be compiled as test.exe.
Private Sub Form_Load()
Dim ex As Excel.Application
Set ex = New Application
ex.Workbooks.Open "c:\a.xls"
ex.Workbooks(1).PrintOut
ex.Quit
Set ex = Nothing
MsgBox "a"
End Sub

I have try to schedule the test.exe at a time Daily or at system startup.
I can not reproduce the problem. When I am not login to the system, the
task will be executed.
The account I set in the task schedule run as is an account in
administrators groups.

You may have a try and let me know the result.
I would like you can post the code you test on your machine so that I can
reproduce the problem.
In addition, which account did you run your task in?


Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
From: "Joshua Campbell" <[email protected]>
References: <[email protected]>
<[email protected]>
Subject: Re: Imperonsate?
Date: Mon, 25 Aug 2003 11:26:05 -0400
Lines: 77
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.languages.vb
NNTP-Posting-Host: 205.152.115.197
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:130241
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

Even then it does not print correctly unless I have the server logged
in
as
the user.

Joshua


Hi Joshua,

When set the schedule task in the windows interface, you may set the
account to run the schedule task.
You may do by following steps.
1. Navigated to Start/Control Panel/Shceduled Tasks/Add Scheduled Tasks
2. Click Next
3. Click Browse button to select the program you want to schedule.
4. Schedule the task in one mode[Daily, Weekly,.....], here I select
"When
I log on", click next.
5. Input the Username and account at which you want to run your task.
Click Next.
6. Click finish.

You may have a try and let me the result.



Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no
rights.
From: "Joshua Campbell" <[email protected]>
Subject: Imperonsate?
Date: Fri, 22 Aug 2003 08:10:04 -0400
Lines: 17
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.languages.vb
NNTP-Posting-Host: 205.152.115.197
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:129660
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

I have a program that I have written in VB.NET that parses a file out,
places data in Excel fields, and then prints out the Excel to Distiller
so
I
can create a PDF. I have this as a scheduled task. This works fine
whenever I have the machine logged in and locked. However, if I do not
have
the machine logged in, then I get printer errors. So, I am thinking
that
if
I were to make the program impersonate the user, then the printers will
work
correctly. So, how do I impersonate a user?



Thanks.

Joshua
 
Hi Joshua,

I want to confirm one thing that when you print to a common printer but not
a adobe distiller printer, did your program works?
If so, I think the problem is that the adobe distiller will output the file
to the current login user's desktop if you let the prompt dialog not show.
I am not expert with adobe distiller, and I donot know if you set the
output file to a pre-setting destination.
In my test ,the output pdf file will output to the current login user's
desktop by default. Then when the adobe distiller want to write the pdf
file to the current user's desktop,
he can not find the desktop directory, as a result, the printer job failed.
I do not know how adobe distiller deal with the issue, even if the user's
desktop directory is exist, but he did not login.
If you can not set the destination of output pdf file, You may contact with
adobe to see if the option is available.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
--------------------
Reply-To: "Joshua Campbell" <[email protected]>
From: "Joshua Campbell" <[email protected]>
References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
Subject: Re: Imperonsate?
Date: Wed, 27 Aug 2003 07:38:54 -0400
Lines: 246
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.languages.vb
NNTP-Posting-Host: 205.152.115.197
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:131069
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

No, it does not prompt with a save dialog. That is a setting in Distiller.
Please keep in mind that the program works perfectly well and
programmatically generates 1000's of PDFs a day without a problem, except
that I have to be logged in in order for the print to work.


Peter Huang said:
Hi Joshua,

You may try to modify your code to print to a common printer to see if the
problem exist.
I think when you print to a adobe distiller printer, it will open a dialog
for you to save to a pdf file.


Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
--------------------
Reply-To: "Joshua Campbell" <[email protected]>
From: "Joshua Campbell" <[email protected]>
References: <[email protected]>
<[email protected]>
Subject: Re: Imperonsate?
Date: Tue, 26 Aug 2003 07:49:55 -0400
Lines: 186
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.languages.vb
NNTP-Posting-Host: 205.152.115.197
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:130545
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

The account that is being used is a domain account that is also a local
administrator of that machine. The print program that you gave would
probably work as a scheduled task. But, let me attach the code below so you
can see exactly what I'm doing.

Dim rngPrint As Excel.Range
Dim shp As Excel.Shape
Dim szAddress As String
Try
If TypeOf xlbook.ActiveSheet Is Excel.Worksheet Then
With xlbook.ActiveSheet
If Len(xlsheet.PageSetup.PrintArea) Then
szAddress = xlsheet.PageSetup.PrintArea Else szAddress =
xlsheet.UsedRange.Address
End With
rngPrint = xlsheet.Range(szAddress)
With rngPrint

.CopyPicture(Appearance:=Excel.XlPictureAppearance.xlScreen,
Format:=Excel.XlCopyPictureFormat.xlBitmap)
With .Parent

rngPrint.Worksheet.Paste(Destination:=rngPrint)
xlsheet.Application.ActivePrinter =
config.AppSettings("PrinterName") 'Adobe Distiller

xlsheet.Application.ActiveWindow.SelectedSheets.PrintOut(Copies:=1,
Collate:=True)
End With
End With
End If
Catch e2 As Exception
EventLog.WriteEntry("Invoices to PDF Application",
"There was an error printing/saving the PDF." & vbCrLf & e2.Message,
EventLogEntryType.Error, 1, 1)
bErrors = True
End Try

So, in this example, it is putting in the background image and then printing
off to a PDF. I am using Adobe Distiller 5.0 to accomplish this.

Joshua



Hi Joshua,

Could you tell me in what account did you run your program in?
Here is my code to test. It will be compiled as test.exe.
Private Sub Form_Load()
Dim ex As Excel.Application
Set ex = New Application
ex.Workbooks.Open "c:\a.xls"
ex.Workbooks(1).PrintOut
ex.Quit
Set ex = Nothing
MsgBox "a"
End Sub

I have try to schedule the test.exe at a time Daily or at system startup.
I can not reproduce the problem. When I am not login to the system, the
task will be executed.
The account I set in the task schedule run as is an account in
administrators groups.

You may have a try and let me know the result.
I would like you can post the code you test on your machine so that I can
reproduce the problem.
In addition, which account did you run your task in?


Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
From: "Joshua Campbell" <[email protected]>
References: <[email protected]>
<[email protected]>
Subject: Re: Imperonsate?
Date: Mon, 25 Aug 2003 11:26:05 -0400
Lines: 77
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.languages.vb
NNTP-Posting-Host: 205.152.115.197
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:130241
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

Even then it does not print correctly unless I have the server logged in
as
the user.

Joshua


Hi Joshua,

When set the schedule task in the windows interface, you may set the
account to run the schedule task.
You may do by following steps.
1. Navigated to Start/Control Panel/Shceduled Tasks/Add Scheduled Tasks
2. Click Next
3. Click Browse button to select the program you want to schedule.
4. Schedule the task in one mode[Daily, Weekly,.....], here I select
"When
I log on", click next.
5. Input the Username and account at which you want to run your task.
Click Next.
6. Click finish.

You may have a try and let me the result.



Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no
rights.
Subject: Imperonsate?
Date: Fri, 22 Aug 2003 08:10:04 -0400
Lines: 17
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.languages.vb
NNTP-Posting-Host: 205.152.115.197
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:129660
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

I have a program that I have written in VB.NET that parses a file out,
places data in Excel fields, and then prints out the Excel to
Distiller
so
I
can create a PDF. I have this as a scheduled task. This works fine
whenever I have the machine logged in and locked. However, if I do
not
have
the machine logged in, then I get printer errors. So, I am thinking
that
if
I were to make the program impersonate the user, then the printers
will
work
correctly. So, how do I impersonate a user?



Thanks.

Joshua
 
If you go into the Printer section of the operating system, and open the
properties for Distiller, you can assign a new port to the printer. This
port is the directory that you want your PDFs that have gone through
distiller to go to. So, for both the Production and the Development
servers, this is set to "C:\Program Files\Adobe\Acrobat 5.0\PDF Output".

Yes, the program works fine if I tell it to just use a standard printer.
And I do agree with you that it may be a problem that Distiller can not be
properly initialized unless the user is logged in to the server, but that is
a guess at best. I was hoping that maybe Impersonation would be a way to
get through this problem.

Joshua



Peter Huang said:
Hi Joshua,

I want to confirm one thing that when you print to a common printer but not
a adobe distiller printer, did your program works?
If so, I think the problem is that the adobe distiller will output the file
to the current login user's desktop if you let the prompt dialog not show.
I am not expert with adobe distiller, and I donot know if you set the
output file to a pre-setting destination.
In my test ,the output pdf file will output to the current login user's
desktop by default. Then when the adobe distiller want to write the pdf
file to the current user's desktop,
he can not find the desktop directory, as a result, the printer job failed.
I do not know how adobe distiller deal with the issue, even if the user's
desktop directory is exist, but he did not login.
If you can not set the destination of output pdf file, You may contact with
adobe to see if the option is available.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
--------------------
Reply-To: "Joshua Campbell" <[email protected]>
From: "Joshua Campbell" <[email protected]>
References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
Subject: Re: Imperonsate?
Date: Wed, 27 Aug 2003 07:38:54 -0400
Lines: 246
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.languages.vb
NNTP-Posting-Host: 205.152.115.197
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:131069
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

No, it does not prompt with a save dialog. That is a setting in Distiller.
Please keep in mind that the program works perfectly well and
programmatically generates 1000's of PDFs a day without a problem, except
that I have to be logged in in order for the print to work.


Peter Huang said:
Hi Joshua,

You may try to modify your code to print to a common printer to see if the
problem exist.
I think when you print to a adobe distiller printer, it will open a dialog
for you to save to a pdf file.


Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
From: "Joshua Campbell" <[email protected]>
References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
Subject: Re: Imperonsate?
Date: Tue, 26 Aug 2003 07:49:55 -0400
Lines: 186
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.languages.vb
NNTP-Posting-Host: 205.152.115.197
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:130545
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

The account that is being used is a domain account that is also a local
administrator of that machine. The print program that you gave would
probably work as a scheduled task. But, let me attach the code below so
you
can see exactly what I'm doing.

Dim rngPrint As Excel.Range
Dim shp As Excel.Shape
Dim szAddress As String
Try
If TypeOf xlbook.ActiveSheet Is Excel.Worksheet Then
With xlbook.ActiveSheet
If Len(xlsheet.PageSetup.PrintArea) Then
szAddress = xlsheet.PageSetup.PrintArea Else szAddress =
xlsheet.UsedRange.Address
End With
rngPrint = xlsheet.Range(szAddress)
With rngPrint

.CopyPicture(Appearance:=Excel.XlPictureAppearance.xlScreen,
Format:=Excel.XlCopyPictureFormat.xlBitmap)
With .Parent

rngPrint.Worksheet.Paste(Destination:=rngPrint)
xlsheet.Application.ActivePrinter =
config.AppSettings("PrinterName") 'Adobe Distiller

xlsheet.Application.ActiveWindow.SelectedSheets.PrintOut(Copies:=1,
Collate:=True)
End With
End With
End If
Catch e2 As Exception
EventLog.WriteEntry("Invoices to PDF Application",
"There was an error printing/saving the PDF." & vbCrLf & e2.Message,
EventLogEntryType.Error, 1, 1)
bErrors = True
End Try

So, in this example, it is putting in the background image and then
printing
off to a PDF. I am using Adobe Distiller 5.0 to accomplish this.

Joshua



Hi Joshua,

Could you tell me in what account did you run your program in?
Here is my code to test. It will be compiled as test.exe.
Private Sub Form_Load()
Dim ex As Excel.Application
Set ex = New Application
ex.Workbooks.Open "c:\a.xls"
ex.Workbooks(1).PrintOut
ex.Quit
Set ex = Nothing
MsgBox "a"
End Sub

I have try to schedule the test.exe at a time Daily or at system
startup.
I can not reproduce the problem. When I am not login to the system, the
task will be executed.
The account I set in the task schedule run as is an account in
administrators groups.

You may have a try and let me know the result.
I would like you can post the code you test on your machine so that
I
can
reproduce the problem.
In addition, which account did you run your task in?


Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no
rights.
From: "Joshua Campbell" <[email protected]>
References: <[email protected]>
<[email protected]>
Subject: Re: Imperonsate?
Date: Mon, 25 Aug 2003 11:26:05 -0400
Lines: 77
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.languages.vb
NNTP-Posting-Host: 205.152.115.197
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:130241
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

Even then it does not print correctly unless I have the server
logged
in
as
the user.

Joshua


Hi Joshua,

When set the schedule task in the windows interface, you may set the
account to run the schedule task.
You may do by following steps.
1. Navigated to Start/Control Panel/Shceduled Tasks/Add Scheduled
Tasks
2. Click Next
3. Click Browse button to select the program you want to schedule.
4. Schedule the task in one mode[Daily, Weekly,.....], here I select
"When
I log on", click next.
5. Input the Username and account at which you want to run your task.
Click Next.
6. Click finish.

You may have a try and let me the result.



Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no
rights.
Subject: Imperonsate?
Date: Fri, 22 Aug 2003 08:10:04 -0400
Lines: 17
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.languages.vb
NNTP-Posting-Host: 205.152.115.197
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.languages.vb:129660
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

I have a program that I have written in VB.NET that parses a file
out,
places data in Excel fields, and then prints out the Excel to
Distiller
so
I
can create a PDF. I have this as a scheduled task. This works fine
whenever I have the machine logged in and locked. However, if I do
not
have
the machine logged in, then I get printer errors. So, I am thinking
that
if
I were to make the program impersonate the user, then the printers
will
work
correctly. So, how do I impersonate a user?



Thanks.

Joshua
 
Hi Joshua,

I am researching this issue, I will update you with new information ASAP.

Have a good weekend!


Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
--------------------
Reply-To: "Joshua Campbell" <[email protected]>
From: "Joshua Campbell" <[email protected]>
References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
Subject: Re: Imperonsate?
Date: Thu, 28 Aug 2003 08:28:36 -0400
Lines: 339
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.languages.vb
NNTP-Posting-Host: 205.152.115.197
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:131633
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

If you go into the Printer section of the operating system, and open the
properties for Distiller, you can assign a new port to the printer. This
port is the directory that you want your PDFs that have gone through
distiller to go to. So, for both the Production and the Development
servers, this is set to "C:\Program Files\Adobe\Acrobat 5.0\PDF Output".

Yes, the program works fine if I tell it to just use a standard printer.
And I do agree with you that it may be a problem that Distiller can not be
properly initialized unless the user is logged in to the server, but that is
a guess at best. I was hoping that maybe Impersonation would be a way to
get through this problem.

Joshua



Peter Huang said:
Hi Joshua,

I want to confirm one thing that when you print to a common printer but not
a adobe distiller printer, did your program works?
If so, I think the problem is that the adobe distiller will output the file
to the current login user's desktop if you let the prompt dialog not show.
I am not expert with adobe distiller, and I donot know if you set the
output file to a pre-setting destination.
In my test ,the output pdf file will output to the current login user's
desktop by default. Then when the adobe distiller want to write the pdf
file to the current user's desktop,
he can not find the desktop directory, as a result, the printer job failed.
I do not know how adobe distiller deal with the issue, even if the user's
desktop directory is exist, but he did not login.
If you can not set the destination of output pdf file, You may contact with
adobe to see if the option is available.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
--------------------
Reply-To: "Joshua Campbell" <[email protected]>
From: "Joshua Campbell" <[email protected]>
References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
Subject: Re: Imperonsate?
Date: Wed, 27 Aug 2003 07:38:54 -0400
Lines: 246
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.languages.vb
NNTP-Posting-Host: 205.152.115.197
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:131069
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

No, it does not prompt with a save dialog. That is a setting in Distiller.
Please keep in mind that the program works perfectly well and
programmatically generates 1000's of PDFs a day without a problem, except
that I have to be logged in in order for the print to work.


Hi Joshua,

You may try to modify your code to print to a common printer to see if the
problem exist.
I think when you print to a adobe distiller printer, it will open a dialog
for you to save to a pdf file.


Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
From: "Joshua Campbell" <[email protected]>
References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
Subject: Re: Imperonsate?
Date: Tue, 26 Aug 2003 07:49:55 -0400
Lines: 186
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.languages.vb
NNTP-Posting-Host: 205.152.115.197
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:130545
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

The account that is being used is a domain account that is also a local
administrator of that machine. The print program that you gave would
probably work as a scheduled task. But, let me attach the code below so
you
can see exactly what I'm doing.

Dim rngPrint As Excel.Range
Dim shp As Excel.Shape
Dim szAddress As String
Try
If TypeOf xlbook.ActiveSheet Is Excel.Worksheet Then
With xlbook.ActiveSheet
If Len(xlsheet.PageSetup.PrintArea) Then
szAddress = xlsheet.PageSetup.PrintArea Else szAddress =
xlsheet.UsedRange.Address
End With
rngPrint = xlsheet.Range(szAddress)
With rngPrint

.CopyPicture(Appearance:=Excel.XlPictureAppearance.xlScreen,
Format:=Excel.XlCopyPictureFormat.xlBitmap)
With .Parent

rngPrint.Worksheet.Paste(Destination:=rngPrint)
xlsheet.Application.ActivePrinter =
config.AppSettings("PrinterName") 'Adobe Distiller

xlsheet.Application.ActiveWindow.SelectedSheets.PrintOut(Copies:=1,
Collate:=True)
End With
End With
End If
Catch e2 As Exception
EventLog.WriteEntry("Invoices to PDF Application",
"There was an error printing/saving the PDF." & vbCrLf & e2.Message,
EventLogEntryType.Error, 1, 1)
bErrors = True
End Try

So, in this example, it is putting in the background image and then
printing
off to a PDF. I am using Adobe Distiller 5.0 to accomplish this.

Joshua



Hi Joshua,

Could you tell me in what account did you run your program in?
Here is my code to test. It will be compiled as test.exe.
Private Sub Form_Load()
Dim ex As Excel.Application
Set ex = New Application
ex.Workbooks.Open "c:\a.xls"
ex.Workbooks(1).PrintOut
ex.Quit
Set ex = Nothing
MsgBox "a"
End Sub

I have try to schedule the test.exe at a time Daily or at system
startup.
I can not reproduce the problem. When I am not login to the system, the
task will be executed.
The account I set in the task schedule run as is an account in
administrators groups.

You may have a try and let me know the result.
I would like you can post the code you test on your machine so that I
can
reproduce the problem.
In addition, which account did you run your task in?


Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no
rights.
References: <[email protected]>
<[email protected]>
Subject: Re: Imperonsate?
Date: Mon, 25 Aug 2003 11:26:05 -0400
Lines: 77
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.languages.vb
NNTP-Posting-Host: 205.152.115.197
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:130241
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

Even then it does not print correctly unless I have the server logged
in
as
the user.

Joshua


Hi Joshua,

When set the schedule task in the windows interface, you may set the
account to run the schedule task.
You may do by following steps.
1. Navigated to Start/Control Panel/Shceduled Tasks/Add Scheduled
Tasks
2. Click Next
3. Click Browse button to select the program you want to schedule.
4. Schedule the task in one mode[Daily, Weekly,.....], here I select
"When
I log on", click next.
5. Input the Username and account at which you want to run your
task.
Click Next.
6. Click finish.

You may have a try and let me the result.



Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no
rights.
Subject: Imperonsate?
Date: Fri, 22 Aug 2003 08:10:04 -0400
Lines: 17
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.languages.vb
NNTP-Posting-Host: 205.152.115.197
Path:
cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.languages.vb:129660
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

I have a program that I have written in VB.NET that parses a file
out,
places data in Excel fields, and then prints out the Excel to
Distiller
so
I
can create a PDF. I have this as a scheduled task. This works
fine
whenever I have the machine logged in and locked. However, if
I
do
not
have
the machine logged in, then I get printer errors. So, I am
thinking
that
if
I were to make the program impersonate the user, then the printers
will
work
correctly. So, how do I impersonate a user?



Thanks.

Joshua
 
Thank you.
Joshua


Peter Huang said:
Hi Joshua,

When you configure a task schedule item, you will be asked to indicate an
account used to run the program.
This will impersonate the account (e.g. administrator) .
Since the problem is specific to the Adobe distiller printer, I think the
printer OEM(Adobe) made their printer driver too complicated and it will
depends on something like an application launched when the user logs in or
access to the interactive desktop.

I have tried to load the user profile manually, before the user logged on,
but with no luck.
I have also tried to load the AutoTray.exe file that will be launched when
a user logs on. BTW, the Windows Task Scheduler (2000 and later) does load
the users profile (via LoadUserProfile) when it launches,

With regards to this issue, I suggest you contact Adobe directly to get
more quick and official information.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
--------------------
X-Tomcat-ID: 261690236
References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
MIME-Version: 1.0
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
From: (e-mail address removed) (Peter Huang [MSFT])
Organization: Microsoft
Date: Fri, 29 Aug 2003 11:45:45 GMT
Subject: Re: Imperonsate?
X-Tomcat-NG: microsoft.public.dotnet.languages.vb
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.languages.vb
Lines: 360
Path: cpmsftngxa06.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:132086
NNTP-Posting-Host: TOMCATIMPORT1 10.201.218.122

Hi Joshua,

I am researching this issue, I will update you with new information ASAP.

Have a good weekend!


Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
--------------------
Reply-To: "Joshua Campbell" <[email protected]>
From: "Joshua Campbell" <[email protected]>
References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
Subject: Re: Imperonsate?
Date: Thu, 28 Aug 2003 08:28:36 -0400
Lines: 339
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.languages.vb
NNTP-Posting-Host: 205.152.115.197
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:131633
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

If you go into the Printer section of the operating system, and open the
properties for Distiller, you can assign a new port to the printer. This
port is the directory that you want your PDFs that have gone through
distiller to go to. So, for both the Production and the Development
servers, this is set to "C:\Program Files\Adobe\Acrobat 5.0\PDF Output".

Yes, the program works fine if I tell it to just use a standard printer.
And I do agree with you that it may be a problem that Distiller can not be
properly initialized unless the user is logged in to the server, but
that
is
a guess at best. I was hoping that maybe Impersonation would be a way to
get through this problem.

Joshua



Hi Joshua,

I want to confirm one thing that when you print to a common printer but
not
a adobe distiller printer, did your program works?
If so, I think the problem is that the adobe distiller will output the
file
to the current login user's desktop if you let the prompt dialog not show.
I am not expert with adobe distiller, and I donot know if you set the
output file to a pre-setting destination.
In my test ,the output pdf file will output to the current login user's
desktop by default. Then when the adobe distiller want to write the pdf
file to the current user's desktop,
he can not find the desktop directory, as a result, the printer job
failed.
I do not know how adobe distiller deal with the issue, even if the user's
desktop directory is exist, but he did not login.
If you can not set the destination of output pdf file, You may contact
with
adobe to see if the option is available.

Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
From: "Joshua Campbell" <[email protected]>
References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
Subject: Re: Imperonsate?
Date: Wed, 27 Aug 2003 07:38:54 -0400
Lines: 246
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.languages.vb
NNTP-Posting-Host: 205.152.115.197
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:131069
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

No, it does not prompt with a save dialog. That is a setting in
Distiller.
Please keep in mind that the program works perfectly well and
programmatically generates 1000's of PDFs a day without a problem, except
that I have to be logged in in order for the print to work.


Hi Joshua,

You may try to modify your code to print to a common printer to see if
the
problem exist.
I think when you print to a adobe distiller printer, it will open a
dialog
for you to save to a pdf file.


Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no
rights.
References: <[email protected]>
<[email protected]>
<[email protected]>
<[email protected]>
Subject: Re: Imperonsate?
Date: Tue, 26 Aug 2003 07:49:55 -0400
Lines: 186
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.languages.vb
NNTP-Posting-Host: 205.152.115.197
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.vb:130545
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

The account that is being used is a domain account that is also a
local
administrator of that machine. The print program that you gave would
probably work as a scheduled task. But, let me attach the code below
so
you
can see exactly what I'm doing.

Dim rngPrint As Excel.Range
Dim shp As Excel.Shape
Dim szAddress As String
Try
If TypeOf xlbook.ActiveSheet Is Excel.Worksheet
Then
With xlbook.ActiveSheet
If Len(xlsheet.PageSetup.PrintArea) Then
szAddress = xlsheet.PageSetup.PrintArea Else szAddress =
xlsheet.UsedRange.Address
End With
rngPrint = xlsheet.Range(szAddress)
With rngPrint

.CopyPicture(Appearance:=Excel.XlPictureAppearance.xlScreen,
Format:=Excel.XlCopyPictureFormat.xlBitmap)
With .Parent

rngPrint.Worksheet.Paste(Destination:=rngPrint)
xlsheet.Application.ActivePrinter =
config.AppSettings("PrinterName") 'Adobe Distiller

xlsheet.Application.ActiveWindow.SelectedSheets.PrintOut(Copies:=1,
Collate:=True)
End With
End With
End If
Catch e2 As Exception
EventLog.WriteEntry("Invoices to PDF Application",
"There was an error printing/saving the PDF." & vbCrLf & e2.Message,
EventLogEntryType.Error, 1, 1)
bErrors = True
End Try

So, in this example, it is putting in the background image and then
printing
off to a PDF. I am using Adobe Distiller 5.0 to accomplish this.

Joshua



Hi Joshua,

Could you tell me in what account did you run your program in?
Here is my code to test. It will be compiled as test.exe.
Private Sub Form_Load()
Dim ex As Excel.Application
Set ex = New Application
ex.Workbooks.Open "c:\a.xls"
ex.Workbooks(1).PrintOut
ex.Quit
Set ex = Nothing
MsgBox "a"
End Sub

I have try to schedule the test.exe at a time Daily or at system
startup.
I can not reproduce the problem. When I am not login to the system,
the
task will be executed.
The account I set in the task schedule run as is an account in
administrators groups.

You may have a try and let me know the result.
I would like you can post the code you test on your machine so that
I
can
reproduce the problem.
In addition, which account did you run your task in?


Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no
rights.
References: <[email protected]>
<[email protected]>
Subject: Re: Imperonsate?
Date: Mon, 25 Aug 2003 11:26:05 -0400
Lines: 77
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.languages.vb
NNTP-Posting-Host: 205.152.115.197
Path:
cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP10.phx.gbl
Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.languages.vb:130241
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

Even then it does not print correctly unless I have the server
logged
in
as
the user.

Joshua


message
Hi Joshua,

When set the schedule task in the windows interface, you may set
the
account to run the schedule task.
You may do by following steps.
1. Navigated to Start/Control Panel/Shceduled Tasks/Add Scheduled
Tasks
2. Click Next
3. Click Browse button to select the program you want to
schedule.
4. Schedule the task in one mode[Daily, Weekly,.....], here I
select
"When
I log on", click next.
5. Input the Username and account at which you want to run your
task.
Click Next.
6. Click finish.

You may have a try and let me the result.



Regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! www.microsoft.com/security
This posting is provided "as is" with no warranties and confers
no
rights.


--------------------
Reply-To: "Joshua Campbell"
<[email protected]>
From: "Joshua Campbell"
<[email protected]>
Subject: Imperonsate?
Date: Fri, 22 Aug 2003 08:10:04 -0400
Lines: 17
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <[email protected]>
Newsgroups: microsoft.public.dotnet.languages.vb
NNTP-Posting-Host: 205.152.115.197
Path:
cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftngp13.phx.gbl
Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.languages.vb:129660
X-Tomcat-NG: microsoft.public.dotnet.languages.vb

I have a program that I have written in VB.NET that parses a
file
out,
places data in Excel fields, and then prints out the Excel to
Distiller
so
I
can create a PDF. I have this as a scheduled task. This works
fine
whenever I have the machine logged in and locked. However,
if
I
do
not
have
the machine logged in, then I get printer errors. So, I am
thinking
that
if
I were to make the program impersonate the user, then the
printers
will
work
correctly. So, how do I impersonate a user?



Thanks.

Joshua
 
Back
Top