Shortcuts and monitor copy progr.
Shortcuts and monitor copy progr.
Shortcuts and monitor copy progr.
Shortcuts and monitor copy progr.
Shortcuts and monitor copy progr.
Shortcuts and monitor copy progr. Shortcuts and monitor copy progr. Shortcuts and monitor copy progr. Shortcuts and monitor copy progr. Shortcuts and monitor copy progr. Shortcuts and monitor copy progr. Shortcuts and monitor copy progr. Shortcuts and monitor copy progr.
Shortcuts and monitor copy progr. Shortcuts and monitor copy progr.
Shortcuts and monitor copy progr.
Go Back  Xtreme Visual Basic Talk > > > Shortcuts and monitor copy progr.


Reply
 
Thread Tools Display Modes
  #1  
Old 03-08-2004, 02:19 PM
bilmks bilmks is offline
Newcomer
 
Join Date: Mar 2004
Posts: 17
Default Shortcuts and monitor copy progr.


I have 2 questions. How can i create shortcuts with VB.net. Also how can i monitor the progress when i copy a large file?
Reply With Quote
  #2  
Old 03-08-2004, 04:27 PM
Csharp's Avatar
CsharpShortcuts and monitor copy progr. Csharp is offline
Senior Contributor

* Expert *
 
Join Date: Jul 2003
Location: Ashby, Leicestershire.
Posts: 967
Default

to monitor the progress of a file when copying from one directory to another ...

Code:
	Public Structure SHFILEOPSTRUCT
		Public hWnd As Integer	
		Public wFunc As Integer
		Public pFrom As String
		Public pTo As String
		Public fFlags As Integer
		Public fAborted As Integer
		Public hNameMaps As Integer
		Public sProgress As String
	End Structure
 
	Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (ByRef lpFileOp As SHFILEOPSTRUCT) As Integer
	Private Const FO_COPY As Integer = &H2
	Private Const FOF_SILENT As Integer = &H4 '/// this will hide the progress box (do NOT use if you wish to see progress )
	
	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
		Dim shStructure As New SHFILEOPSTRUCT()
		Dim currentpath As String = "C:\testing" '/// folder to copy
		Dim newpath As String = "F:\testing" '/// new path
		With shStructure
			.wFunc = FO_COPY
			.pFrom = currentpath
			.pTo = newpath
		End With
		SHFileOperation(shStructure)
	End Sub
__________________
~~ please don't PM me regarding code, I only reply to personnal messages ~~
Reply With Quote
  #3  
Old 03-11-2004, 07:18 AM
bilmks bilmks is offline
Newcomer
 
Join Date: Mar 2004
Posts: 17
Default

Thanks a lot Csharp. Although it's not very clear for me (not so good with API) it works
Reply With Quote
  #4  
Old 03-11-2004, 09:39 AM
OnErr0r's Avatar
OnErr0rShortcuts and monitor copy progr. OnErr0r is offline
Obsessive OPtimizer

Administrator
* Guru *
 
Join Date: Jun 2002
Location: Debug Window
Posts: 13,774
Default

The SHFILEOPSTRUCTA should be packed with 1 byte alignment. If you attempt to access namemappings, aborted or progress you'll run into problems without it. Also, passing the hwnd will make the dialog modal. Note that fFlags should be a short, not an integer.

Code:
Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (ByRef lpFileOp As SHFILEOPSTRUCTA) As Integer <StructLayout(LayoutKind.Sequential, Pack:=1)> Public Structure SHFILEOPSTRUCTA Public hwnd As IntPtr Public wFunc As Integer Public pFrom As String Public pTo As String Public fFlags As Short Public fAnyOperationsAborted As Integer Public hNameMappings As IntPtr Public lpszProgressTitle As String End Structure
Reply With Quote
  #5  
Old 04-04-2004, 10:59 PM
sonicdemonic sonicdemonic is offline
Junior Contributor
 
Join Date: Feb 2004
Location: Indiana
Posts: 261
Default

Quote:
Originally Posted by OnErr0r
The SHFILEOPSTRUCTA should be packed with 1 byte alignment. If you attempt to access namemappings, aborted or progress you'll run into problems without it. Also, passing the hwnd will make the dialog modal. Note that fFlags should be a short, not an integer.

Code:
Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (ByRef lpFileOp As SHFILEOPSTRUCTA) As Integer <StructLayout(LayoutKind.Sequential, Pack:=1)> Public Structure SHFILEOPSTRUCTA Public hwnd As IntPtr Public wFunc As Integer Public pFrom As String Public pTo As String Public fFlags As Short Public fAnyOperationsAborted As Integer Public hNameMappings As IntPtr Public lpszProgressTitle As String End Structure
The line...
<StructLayout(LayoutKind.Sequential, Pack:=1)>

return an error for me..
Reply With Quote
  #6  
Old 04-05-2004, 07:08 AM
MKoslof's Avatar
MKoslofShortcuts and monitor copy progr. MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

What was the error message? OnError's example is a preferred method of mine as well.
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
Reply With Quote
  #7  
Old 04-05-2004, 07:55 AM
sonicdemonic sonicdemonic is offline
Junior Contributor
 
Join Date: Feb 2004
Location: Indiana
Posts: 261
Default

<StructLayout(LayoutKind.Sequential, Pack:=1)>

vb.net is telling me..

"Type 'StructLayout' is not defined..

Here is the code...
Code:
Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (ByRef lpFileOp As SHFILEOPSTRUCT) As Integer Private Const FO_COPY As Integer = &H2 Private Const FOF_SILENT As Integer = &H4 '/// this will hide the progress box (do NOT use if you wish to see progress ) <StructLayout(LayoutKind.Sequential, Pack:=1)> Public Structure SHFILEOPSTRUCT Public hwnd As IntPtr Public wFunc As Integer Public pFrom As String Public pTo As String Public fFlags As Short Public fAnyOperationsAborted As Integer Public hNameMappings As IntPtr Public lpszProgressTitle As String End Structure Function File_Copy_Diag(ByVal Copy_File As String, ByVal Paste_File As String) Dim shStructure As New SHFILEOPSTRUCT Dim currentpath As String = Copy_File '/// folder to copy Dim newpath As String = Paste_File '/// new path With shStructure .wFunc = FO_COPY .pFrom = currentpath .pTo = newpath End With SHFileOperation(shStructure) End Function

Last edited by sonicdemonic; 04-05-2004 at 10:00 PM.
Reply With Quote
  #8  
Old 04-06-2004, 07:18 AM
MKoslof's Avatar
MKoslofShortcuts and monitor copy progr. MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

Try this..notice the slight differences:

Code:
<StructLayout(LayoutKind.Sequential,Pack:=1,CharSet:=CharSet.Auto)> _ Private Structure SHFILEOPSTRUCT Public hwnd As IntPtr Public wFunc As Integer Public pFrom As String Public pTo As String Public fFlags As Short Public fAnyOperationsAborted As Boolean Public hNameMappings As IntPtr Public lpszProgressTitle As String End Structure Private Declare Auto Function SHFileOperation Lib "shell32.dll" (ByRef lpFileOp As SHFILEOPSTRUCT) As Integer
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
Reply With Quote
  #9  
Old 04-06-2004, 09:08 AM
sonicdemonic sonicdemonic is offline
Junior Contributor
 
Join Date: Feb 2004
Location: Indiana
Posts: 261
Question

Ughhh..

Do need to import something with this..??
VB is still telling me that StructLayout is not defined..

Also , now it doesn't attemp to copy files.. I have to comment out the sctructlayout line and when run it I dont get error or copied files. Basicly nothing happens with the script.

Last edited by sonicdemonic; 04-06-2004 at 09:16 AM.
Reply With Quote
  #10  
Old 04-06-2004, 02:37 PM
MKoslof's Avatar
MKoslofShortcuts and monitor copy progr. MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

hmmm..are you currently importing any system classes? If so, what are you using. Can you post your entire update code piece, including everything within this class/module?
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
Reply With Quote
  #11  
Old 04-06-2004, 09:51 PM
sonicdemonic sonicdemonic is offline
Junior Contributor
 
Join Date: Feb 2004
Location: Indiana
Posts: 261
Default

Quote:
Originally Posted by MKoslof
hmmm..are you currently importing any system classes? If so, what are you using. Can you post your entire update code piece, including everything within this class/module?
Here is my module..

Code:
Module FileCopyDiag Private Declare Auto Function SHFileOperation Lib "shell32.dll" (ByVal ByReflpFileOp As SHFILEOPSTRUCT) As Integer Private Const FO_COPY As Integer = &H2 Private Const FOF_SILENT As Integer = &H4 '/// this will hide the progress box (do NOT use if you wish to see progress ) <StructLayout(LayoutKind.Sequential, Pack:=1, CharSet:=CharSet.Auto)> _ Private Structure SHFILEOPSTRUCT Public hwnd As IntPtr Public wFunc As Integer Public pFrom As String Public pTo As String Public fFlags As Short Public fAnyOperationsAborted As Boolean Public hNameMappings As IntPtr Public lpszProgressTitle As String End Structure Function File_Copy_Diag(ByVal Copy_File As String, ByVal Paste_File As String) Dim shStructure As New SHFILEOPSTRUCT Dim currentpath As String = Copy_File '/// folder to copy Dim newpath As String = Paste_File '/// new path With shStructure .wFunc = FO_COPY .pFrom = currentpath .pTo = newpath End With SHFileOperation(shStructure) End Function End Module
Vb says that " StructLayout " is not defined
Reply With Quote
  #12  
Old 04-07-2004, 09:31 AM
MKoslof's Avatar
MKoslofShortcuts and monitor copy progr. MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

Hmmm..well I was going to tell you to remove the Alias, but you have already done that in your code...do you have the proper imports statement? Add this import and see if it helps:

Option Explicit On
Imports System.Runtime.InteropServices

I always like to use Option Explicit in my code. I don't think you need any marshalling in this...but we may need to try that next.
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
Reply With Quote
  #13  
Old 04-07-2004, 06:56 PM
sonicdemonic sonicdemonic is offline
Junior Contributor
 
Join Date: Feb 2004
Location: Indiana
Posts: 261
Cool Yay!!!

Sweet, well After I added that it fixed the problem with vb returning the error on that one line but it still wouldnt copy. After some debugging/guessing I got it!
I appreciate it!

Last edited by sonicdemonic; 04-07-2004 at 07:12 PM.
Reply With Quote
  #14  
Old 04-08-2004, 06:27 AM
MKoslof's Avatar
MKoslofShortcuts and monitor copy progr. MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

You also want to do some research on "Marshalling". The more you do with API in .Net, the more you'll need to use it. Good luck.
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
Reply With Quote
  #15  
Old 04-10-2004, 10:02 AM
OnErr0r's Avatar
OnErr0rShortcuts and monitor copy progr. OnErr0r is offline
Obsessive OPtimizer

Administrator
* Guru *
 
Join Date: Jun 2002
Location: Debug Window
Posts: 13,774
Default

Just a quick note (I've been out of town for a week): The fAnyOperationsAborted field of the SHFILEOPSTRUCTA should be an integer (as I mentioned previously) not a boolean. Boolean is two bytes and integer is four. Using the incorrect size field will throw off the hNameMappings and pszProgressTitle fields.
Reply With Quote
  #16  
Old 05-27-2004, 09:18 PM
Code Cowboy Code Cowboy is offline
Newcomer
 
Join Date: May 2004
Posts: 1
Default Excellent code...but...

1. doesn't seem to like copying to a non-mapped resource...

ie FROM: c:\temp\somefile.zip TO: \\servername\share\somefile.zip


2. what is the lpszProgressTitle in the structure for? I tried to set it and it makes the whole function blow up.
Reply With Quote
  #17  
Old 05-27-2004, 09:24 PM
OnErr0r's Avatar
OnErr0rShortcuts and monitor copy progr. OnErr0r is offline
Obsessive OPtimizer

Administrator
* Guru *
 
Join Date: Jun 2002
Location: Debug Window
Posts: 13,774
Default

2.) To set the Title bar of the progress dialog.

Did you use the SHFILEOPSTRUCT as I defined it?
Reply With Quote
  #18  
Old 05-28-2004, 06:11 AM
MKoslof's Avatar
MKoslofShortcuts and monitor copy progr. MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

I have never had any problems trying to use a mapped drive. As OnErrorOr has stated, what is your current code? Can you post what you are using
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
Reply With Quote
  #19  
Old 05-28-2004, 05:10 PM
sonicdemonic sonicdemonic is offline
Junior Contributor
 
Join Date: Feb 2004
Location: Indiana
Posts: 261
Cool

This is the code from my module for file copy
Code:
Option Explicit On Imports System.Runtime.InteropServices Module FileCopyDiag Private Const FO_COPY As Integer = &H2 Private Const FOF_SILENT As Integer = &H4 '/// this will hide the progress box (do NOT use if you wish to see progress ) Private Declare Function SHFileOperation Lib "shell32.dll" Alias "SHFileOperationA" (ByRef lpFileOp As SHFILEOPSTRUCT) As Integer <StructLayout(LayoutKind.Sequential, Pack:=1)> Public Structure SHFILEOPSTRUCT Public hwnd As IntPtr Public wFunc As Integer Public pFrom As String Public pTo As String Public fFlags As Short Public fAnyOperationsAborted As Integer Public hNameMappings As IntPtr Public lpszProgressTitle As String End Structure Function File_Copy_Diag(ByVal Copy_File As String, ByVal Paste_File As String) Dim shStructure As New SHFILEOPSTRUCT Dim currentpath As String = Copy_File Dim newpath As String = Paste_File With shStructure .wFunc = FO_COPY .pFrom = currentpath .pTo = newpath End With SHFileOperation(shStructure) End Function End Module

I was having problems with something before but figured it out ..
I have not tried this with a mapped drive.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Shortcuts and monitor copy progr.
Shortcuts and monitor copy progr.
Shortcuts and monitor copy progr. Shortcuts and monitor copy progr.
Shortcuts and monitor copy progr.
Shortcuts and monitor copy progr.
Shortcuts and monitor copy progr. Shortcuts and monitor copy progr. Shortcuts and monitor copy progr. Shortcuts and monitor copy progr. Shortcuts and monitor copy progr. Shortcuts and monitor copy progr. Shortcuts and monitor copy progr.
Shortcuts and monitor copy progr.
Shortcuts and monitor copy progr.
 
Shortcuts and monitor copy progr.
Shortcuts and monitor copy progr.
 
-->