Jump to content

vbs to autoit, office applications


TheBG
 Share

Recommended Posts

hello all,

i have a vbs script that will go through outlook and detach all pst files.

can these particular commands be run in autoit?

'On Error resume next
Dim objOutlook 'As Outlook.Application
Dim Session 'As Outlook.NameSpace
Dim Store 'As Outlook.Store
Dim Stores 'As Outlook.Stores
Dim objFolder 'As Outlook.Folder

Set objOutlook = CreateObject("Outlook.Application")
Set Session = objOutlook.Session
Set Stores = Session.Stores

For Each Store In Stores

If Store.ExchangeStoreType = 3 then
   Set objFolder = store.GetRootFolder
   Session.RemoveStore objFolder
End If

Next

Also - i need to be able to move the files to a new location on c:\ after they are detached? any thoughts?

Thanks in advance for your help.

Link to comment
Share on other sites

This might work as a conversion.

Global $objOutlook = ObjCreate("Outlook.Application")
Global $Session = $objOutlook.Session
Global $Stores = $Session.Stores

For $Store In $Stores

     If $Store.ExchangeStoreType = 3 Then
          Global $objFolder = $Store.GetRootFolder
          $Session.RemoveStore($objFolder)
     EndIf

Next

Also, look at FileMove in the help file.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

awesome thanks!!!. worked great.

Anyone have any good scripts to search a dir tree for a file type?

the goal is to search @userprofile for *.pst and then move each file to @userprofileOutlookPST folder

Link to comment
Share on other sites

Everything you need to work with Outlook can be found in my OutlookEX UDF (for download please see my signature).

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

thanks everyone... so far, so good.

I can disconnect pst files and move them.

Does anyone have suggestions for multple files with the same name? I need to figure out how to add incremental numbers to the end of the file name, so the file is not overwritten during the move.

yes, I need to use filemove, we have to get these pst files out of the users main directory.

right now I have this:

[/sub]
[sub] [/sub]
[sub][sub]Func MovePST2()
 DirCreate(@UserProfileDir&"OutlookPST")
 ;Sleep(3000)
 $files = _RecFileListToArray(@UserProfileDir, "*.pst", 1, 1, 0, 2)
 $files2 = _RecFileListToArray(@UserProfileDir, "*.pst", 1, 1, 0, 0)[/sub][/sub]
[sub][sub] For $i = 1 To $files[0]
  $trim = StringTrimRight($files2[$i], 4)
  MsgBox(4096, "trim", $trim);returns target name
  MsgBox(4096, "info", $files[$i]);returns full path
  MsgBox(4096, "info", $files2[$i]);return recursive path
  If FileExists(@UserProfileDir&"OutlookPST"&$trim&""&$files2[$i]) Then
   DirCreate(@UserProfileDir&"OutlookPST"&$trim&"-1")
   FileMove($files[$i], @UserProfileDir&"OutlookPST"&$trim&""&$trim, 8)
   ;FileMove($files[$i], @UserProfileDir&"OutlookPST"&$trim&""&$trim&"-1.pst", 8)
   Else
   DirCreate(@UserProfileDir&"OutlookPST"&$trim)
   FileMove($files[$i], @UserProfileDir&"OutlookPST"&$trim, 8)
   EndIf
  Next
EndFunc[/sub][/sub]
[sub]
Link to comment
Share on other sites

Afternoon,

I saw your response to my query for closing pst files.

Could you show me hwo to use your udf to find all psts and close them?

Also - i cant seem to find the download. I get 'invalid' zip files from the download page.

thanks!

To close all PST files currently open in Outlook use the following code:

$oOL = _OL_Open()
$aStores = _OL_StoreGet($oOL)
For $i = 1 to $aStores[0][0]
If $aStores[$i][4] = True Then
     _OL_PSTClose($aStores[$i][0]
EndIf
Next
_OL_Close()
There is no error checking in this code and the code is untested.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

I have noticed something when closing PST file that may affect copy.

When i close a PST file it stays open/outlook keeps it locked until i close the Outlook itself.

You can tell easy when in the PST folder and seeing hidden files - you can see the pst temp file:

"~archive.pst.tmp".

Link to comment
Share on other sites

Thanks water!

there were some issues with the code, but I fixed it:

Func DisconnectPSTEX()
Local $oOL = _OL_Open()
Local $aStores = _OL_StoreGet($oOL)
For $i = 1 to $aStores[0][0]
  If $aStores[$i][4] = True Then
  _OL_PSTClose($oOL,$aStores[$i][0])
  EndIf
Next
_OL_Close($oOL)
EndFunc

Question - I started getting security prompts about outlook being accessed. thoughts?

Link to comment
Share on other sites

Haven't seen security warnings when accessing a store before but you shouldn't get such prompts when an AV software is installed.

Can you post a screenshot of the prompt you get?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Do you have an Anti-Virus software installed. If Outllook determines that up-to-date AV software is installed those security warnings do not pop up.

You can pass the name of a compiled AutoIt script to _OL_Open to click away thos pop ups.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

ok, i figured out how to use _OL_Warnings :-)

I have noticed something when closing PST file that may affect copy.

When i close a PST file it stays open/outlook keeps it locked until i close the Outlook itself.

You can tell easy when in the PST folder and seeing hidden files - you can see the pst temp file:

"~archive.pst.tmp".

yes, I ran into this problem too. I do make outlook close prior to trying to move the files.

But on occasion the files dont move. Im assuming do to it thinking the files are still in use.

Link to comment
Share on other sites

Hello again,

So, I have my script working pretty well.

Can anyone help me with using _FileinUse?

I was curious how to make it wait until a file is not longer is use... like a while or do statment?

Func MovePST2()
local $files, $files2, $trim, $i
$files = _RecFileListToArray(@UserProfileDir, "*.pst", 1, 1, 0, 2)
$files2 = _RecFileListToArray(@UserProfileDir, "*.pst", 1, 1, 0, 0)
DirCreate(@UserProfileDir&"OutlookPST")
Sleep(1000)
Local $x = _FileInUse($files[$i])
While $x == 0
For $i = 1 To $files[0]
  $trim = StringTrimRight($files2[$i], 4)
   ;MsgBox(4096, "", ".tmp file found!")
    If FileExists(@UserProfileDir&"OutlookPST"&$trim) Then
    Else
     If FileExists(@UserProfileDir&"OutlookPST"&$trim&""&$files2[$i]) Then
      DirCreate(@UserProfileDir&"OutlookPST"&$trim&"-"&$i)
      Sleep(3000)
      FileMove($files[$i], @UserProfileDir&"OutlookPST"&$trim&"-"&$i&"", 9)
      Sleep(3000)
     Else
      DirCreate(@UserProfileDir&"OutlookPST"&$trim)
      Sleep(3000)
      FileMove($files[$i], @UserProfileDir&"OutlookPST"&$trim, 9)
      Sleep(3000)
     EndIf
    EndIf
  Sleep(1000)
Next
WEnd
EndFunc
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...