- Can anyone help me with running vbs from itself but with administrator rights? I need rename computer with Windows 8 via VBScript, but it's possible only if I run my script through administrator command line (CMD → Run as Administrator → runScript.vbs). If I start script with classic CMD the computer isn't renamed.
- How to Create and Run a CMD batch file. To prepare a new batch script, save the file as plain ASCII text with the file extension.CMD. Run a batch file. A batch file can be run by simply double clicking in Windows explorer, or by typing the name/path at the command line, optionally passing any parameters needed.
Can Access run vb commands stored in a file? (Access 2003 sp3)We are getting ready to ditch our Novell server for a Microsoft server, and at the same time change our directory structure.As most of our Access files use linked tables, our sysadmin wants to refresh all the links programmatically using power shell to locate and open Access files, whereupon they would run a vbscript which would change the table linking parameters to conformto the new directory structure.Any idea if something like this is possible, or any other suggestions on how to change links programmatically?Thanks! I don't think this is the correct approach. However, you don't need to open the files in Access in order to relink them. You can write one procedure in VBScript - really VBScript, not VBA within Access, which I think is what you were asking- to process a list of Access databases and relink the linked tables in each one, where those tables are linked to particular files or in a particular directory structure. This is because you can create and use DAO objects from VBScript, and table linksare properties of DAO TableDef objects residing in a DAO Database object.The logic you would use in this VBScript procedure to do the actual relinking (once you've determined which tables need to be relinked and what they need to be relinked to - would be similar to the relinking code posted elsewhere, such as at the link ChrisWard posted.Dirk Goldgar, MS Access MVPAccess tips: www.datagnostics.com/tips.html.
ObjShell.run('cscript C: scripts demo.vbs') “Tell the truth and run” Yugoslavian proverb. Related.Exec - Execute command, returning an object.ShellExecute - Run an application in the Windows Shell cscript - Run a VB Script.vbs file Arguments - Passing arguments to a script Equivalent Windows CMD command: START - Start a program or command.
I do know that I have sql server 2008 developer (64bit) running on this workstation. Does that make my workstation 64 bit?If you're runing 64-bit SQL Server, then you must be running 64-bit Windows. 64-bit OS can run 32-bit applications, but not vice versa. Maybe that's the issue, somehow, but I can't test it at the moment as I don't have a 64-bit machine handy.I'm curious about what may be going wrong, and whether it's an unusual quirk of your system, or something predictable.Here's an idea for investigating it, if you've a mind to. On your 64-bit Windows, start a 32-bit command prompt, which I think youcan do by executingC:WindowssysWOW64cmd.exeIn that 32-bit command prompt window, run your dbTableList.vbs script.
If this time it works, that will mean the issue was due to the 'bit-ness' conflict - probably the OS couldn't locate the 32-bit library. If it doesn't work, well, we're nocloser than we were.It's actually issues like this why I favor ADO for data Access over other options because - historically - I have had way less trouble with ADO than anything else.I certainly don't argue with your using what works best for you. DAO is optimized for working with Access databases, and lets you manipulate them at a level that ADO doesn't. ADO is generalized to work with a large variety of different data sources,and has some really nice features that DAO doesn't have.Note: ADO.Net is even less troublesome than ADO. I can read up a whole table to my custom.Net library and write/read data to/from any sql server in our network without a hitch.ADO.Net is great, but of course that means that.Net has to be installed on the system, and that's a much bigger footprint than the DAO and ADO libraries combined.
Granted, at this point it's probably reasonable to expect Windows systems to have.Netinstalled, but it is a dependency.Dirk Goldgar, MS Access MVPAccess tips: www.datagnostics.com/tips.html. I don't think this is the correct approach. However, you don't need to open the files in Access in order to relink them. You can write one procedure in VBScript - really VBScript, not VBA within Access, which I think is what you were asking- to process a list of Access databases and relink the linked tables in each one, where those tables are linked to particular files or in a particular directory structure. This is because you can create and use DAO objects from VBScript, and table linksare properties of DAO TableDef objects residing in a DAO Database object.The logic you would use in this VBScript procedure to do the actual relinking (once you've determined which tables need to be relinked and what they need to be relinked to - would be similar to the relinking code posted elsewhere, such as at the link ChrisWard posted.Dirk Goldgar, MS Access MVPAccess tips: www.datagnostics.com/tips.html.
Just to make sure we are on the same page - vbScript is a VBA type script that you would write in Notepad (Notepad is a fully programmable application - supports vbScript, jScript, xml, html, and probably more stuff). VbScript also supports ADO, but Idon't think it supports DAO - DAO is native to Access. VbScript also support ADO, but I don't think it supports DAO - DAO is native to Access.Yes, VBScript supports DAO, so long as it is installed. Until recently, the Jet database engine and DAO object library were installed on all Windows systems; however, I don't think this is still the case. I'm not sure the new ACEDAO library (supportingthe.accdb format) is.not. installed on all systems, as that is a spinoff of the DAO library that was created specifically for Access.
However, any computer that has Access installed has, at the least, some version of the DAO libraryinstalled, and VBScript executed on that computer can use DAO objects.Dirk Goldgar, MS Access MVPAccess tips: www.datagnostics.com/tips.html. VBscript does not support DAO. I just tried it (this is the same workstation that I am running Access on, so I know that I have the DAO library):Here's the script that I tried Dim DbsDim tdfDim DBDim s1Set Dbs = CreateObject('DAO.DBEngine.36')Set DB = Dbs.OpenDatabase('C:CodetestAccdb2test.mdb')For Each tdf In DB.TableDefsIf tdf.Attributes = 0 And tdf.Attributes 2 Thens1 = s1 + ', ' + tdf.NameEnd IfNextDB.CloseSet Dbs = NothingWScript.Echo 'this is a test' + s1WScript.QuitRich P. VBscript does not support DAO. I'm running Access 2003 (full version) running on a win7 workstation, and I have the Access 2010 runtime (which the acc2010 is what I use with.Net - which is the other reason I even use.Net with Access) on this particular workstation.I created another mdb with only 1 table, but I can't get past the createObject statement - using the DAO library. ADO is OK, but I can't get a list of tables with ADO from vbscript.
I also tried from IE in an htm file, but turns out that IE (11)it is documented that IE11 does not support vbscript.Rich P. I'm puzzled what could be going wrong on your system, unless (grasping at straws) it has something to do with the 'bit-ness' of the operating system. Is your Win7 64-bit? Please let me know if CreateObject('DAO.DBEngine.120') worksfor you.I wonder if you can use ADOX via VBScript, which would let you get a list of tables. I haven't tried it.
Also, there's probably a special schema you can query with ADO that would return a list of tables. But I don't remember what it is.Dirk Goldgar, MS Access MVPAccess tips: www.datagnostics.com/tips.html. I tried DAO.DBEngine.120 but that didn't get it either. Not sure bout my win7. We have a guy that put em all together. I do know that I have sql server 2008 developer (64bit) running on this workstation.
Does that make my workstation64 bit? I suspect that when I loaded the acc2010 runtime - that may have tweaked things a little bit. I would load my full version acc2010 on here, but I am still supporting some legacy acc2003 ADPs, mdbs. So gotta stay consistent with everyoneelse (but also running office 2010 just Acc2003 - for the legacy stuff).It's actually issues like this why I favor ADO for data Access over other options because - historically - I have had way less trouble with ADO than anything else.
Note: ADO.Net is even less troublesome than ADO. I can read up a wholetable to my custom.Net library and write/read data to/from any sql server in our network without a hitch.Rich P. I do know that I have sql server 2008 developer (64bit) running on this workstation. Does that make my workstation 64 bit?If you're runing 64-bit SQL Server, then you must be running 64-bit Windows. 64-bit OS can run 32-bit applications, but not vice versa. Maybe that's the issue, somehow, but I can't test it at the moment as I don't have a 64-bit machine handy.I'm curious about what may be going wrong, and whether it's an unusual quirk of your system, or something predictable.Here's an idea for investigating it, if you've a mind to. On your 64-bit Windows, start a 32-bit command prompt, which I think youcan do by executingC:WindowssysWOW64cmd.exeIn that 32-bit command prompt window, run your dbTableList.vbs script.
If this time it works, that will mean the issue was due to the 'bit-ness' conflict - probably the OS couldn't locate the 32-bit library. If it doesn't work, well, we're nocloser than we were.It's actually issues like this why I favor ADO for data Access over other options because - historically - I have had way less trouble with ADO than anything else.I certainly don't argue with your using what works best for you. DAO is optimized for working with Access databases, and lets you manipulate them at a level that ADO doesn't. ADO is generalized to work with a large variety of different data sources,and has some really nice features that DAO doesn't have.Note: ADO.Net is even less troublesome than ADO. I can read up a whole table to my custom.Net library and write/read data to/from any sql server in our network without a hitch.ADO.Net is great, but of course that means that.Net has to be installed on the system, and that's a much bigger footprint than the DAO and ADO libraries combined. Granted, at this point it's probably reasonable to expect Windows systems to have.Netinstalled, but it is a dependency.Dirk Goldgar, MS Access MVPAccess tips: www.datagnostics.com/tips.html. Changing toC:WindowssysWOW64cmd.exeYes, that worked!
It WAS the bitless thing. This is actually quite cool. Who knew I would find another use for DAO (after hijacking this thread:).Very cool discovery for 64 bit win7. I guess I really AM running 64 bit windows.Very interesting. Thanks for checking that out. I'm amused that we came to this from opposite directions: me saying 'Of course you can use DAO in VBScript!'
And you saying 'Of course you can't!' - finally arriving at 'You can, but.' .If one were writing some process to automate a mass-manipulation of Access databases, as in the OP here, one would have to take into account the bit-ness of the operating system executing the procedure, so that it could invoke the VBScript via a 32-bit commandshell if necessary. Unless there's some other way around it, which I suppose is possible.Dirk Goldgar, MS Access MVPAccess tips: www.datagnostics.com/tips.html.
I am pulling all hair out at the moment over something that I feel should be simple!I have created a VBScript to copy a folder from a network share to local disk C: (which has been successful) but am having difficulty trying to run a batch file which is inside that folder.I can run the batch file if I double click it but no matter what methods I have tried (Set ObjShell.run or run = 'filename') etc. It just will not work!could somebody please tell me how I would go about running a batch file within a local folder.here is my current script (The part in bold italics works): Set FSO =CreateObject('scripting.FileSystemObject') FSO.CopyFolder 'myservermsifolderklitewindowsseven', 'c:',Truedim shellset shell=createobject('wscript.shell')shell.run='C:klitewindowssevenklcpfullunattended.bat'set shell=nothingAgain from the 'dim shell' onwards I cannot get a batch file to run. Hi Richard,Just tried and that didn't work either:-(It doesn't state any error messages, I just double click it, and nothing happens, yet the folder copies from the server to the C: driveIf you paste this at a command prompt what happens.C:klitewindowssevenklcpfullunattended.batOpen a comamnd prompt and paste it into the window. You are probably getting an error.Tp prove this workse place this command at teh top of the batch file:PAUSEThis will cause the batch file to pause so you can see that it is executing. Any critical error can abort teh barch file so fast you may not see it.You can also change this line to force the batch file to stay visible.shell.Run '%comspec% /K C:klitewindowssevenklcpfullunattended.bat', 1, TrueNotice the /c is now /K anf th e0 is a 1.This is how to debug this kind of problem.
Be sure you rVBS is nnot getting an error. You should check for errors by running the VBS from a command prompt.
It can also be errorin before the batch file is launched.¯(ツ)/¯. Hi Bill,Thanks, but I still couldn't get that to work, it doesn't appear with any error messages but the.bat file is to run an unattended setup and although when I double click it, it will work. As I understand it, all steps would be in the VBScript.
Run Vbscript From Command Line Silently
The complete VBScript program would be as follows:Option Explicit Dim FSO, shell Set FSO =CreateObject( 'scripting.FileSystemObject')FSO.CopyFolder 'myservermsifolderklitewindowsseven','c:',True set shell=createobject( 'wscript.shell')shell.Run '%comspec% /c C:klitewindowssevenklcpfullunattended.bat', 0,True -This will copy the folder from myserver to the local C: drive, then run the bat file.Richard Mueller - MVP Directory Services. Icom f22sr software windows 7. Hi Richard,Just tried and that didn't work either:-(It doesn't state any error messages, I just double click it, and nothing happens, yet the folder copies from the server to the C: driveIf you paste this at a command prompt what happens.C:klitewindowssevenklcpfullunattended.batOpen a comamnd prompt and paste it into the window. You are probably getting an error.Tp prove this workse place this command at teh top of the batch file:PAUSEThis will cause the batch file to pause so you can see that it is executing. Any critical error can abort teh barch file so fast you may not see it.You can also change this line to force the batch file to stay visible.shell.Run '%comspec% /K C:klitewindowssevenklcpfullunattended.bat', 1, TrueNotice the /c is now /K anf th e0 is a 1.This is how to debug this kind of problem. Be sure you rVBS is nnot getting an error. You should check for errors by running the VBS from a command prompt. It can also be errorin before the batch file is launched.¯(ツ)/¯.
Run Vbs File From Cmd En Youtube
If anybody's still having trouble,I was having a similiar problem because the batch file I ran didn't do what it was supposed to so I re-entered the command manually into PowerShell (Installed on later Windows) and it turned out that when the batch file started, it changed the current operatingdirectory to someplace completely different and it caused issues because the operation needed the working directory to be correct. I also had a similar issue where I had not acknowledged the fact that my executing VBScript was in a directory up one level from the batch file which was being called upon.
My Batch file had relative path instances to other Bat files and directories whichwere broken based on the fact that the current directory where the command shell was running from was in the wrong location. Its pretty obvious now that i thought about it since you are creating the Shell Object from the vbscript what ever directory that residesin would be your Shells current directory.Adding an echo%CD% at the top of the command file is a good give away.Thanks for that reference as it helped me track down my little issue in a matter of a minute or two.SS.